Re: [WICG/webcomponents] Reference Target: How to handle events fired on the reference target by related elements? (Issue #1098)

alice left a comment (WICG/webcomponents#1098)

#### button inside shadow root with `popoverTargetElement` in an ancestor shadow root

```html
<x-popover id="popover">
  <template shadowRootMode="open" shadowRootReferenceTarget="container">
    <style>
      #container {
        /* completely encapsulated styles for the popover */
      }
    </style>
    <x-button id="xButton" data-popovertarget="container">
      <template shadowRootMode="open" shadowRootReferenceTarget="button">
        <button id="button">Toggle</button>
      </template>
    </x-button>
    <div id="container" popover>
     Popover content.
    </div>
  </template>
</x-popover>
```

```js
// somewhere in the custom element definition for <x-button>
button.popoverTargetElement = host.getRootNode().getElementById(dataset.popovertarget);
```

(Steps 1-11 are the same again.)
12. 🆕 When [a shadow root's get the parent](https://dom.spec.whatwg.org/#ref-for-get-the-parent%E2%91%A6) is invoked on the shadow root, we go to the new logic:
   > 1. let _target_ be event’s path’s first struct’s invocation target;
   > 2. if _event_’s composed flag is set, or shadow root is not the root of _target_, return return shadow root’s host;
   > 3. otherwise, if _event_ has an invoker, and _event_'s invoker's root is a shadow-including ancestor of shadow root, return the result of retargeting _target_ against event's triggering element;
   > 4. otherwise, return null.
   
   so _target_ is `container`; shadow root _is_ the root of _target_; event has an invoker, `button`; `button`'s root (the inner shadow root) _is not_ a shadow-including ancestor of shadow root; so, we return null as the parent element.
13. 🆕 Back in event dispatch the path is still just [`container`, shadow root].
14. Event dispatch continues as normal with the given event path
15. 🆕 If [`composedPath()`](https://dom.spec.whatwg.org/#dom-event-composedpath) is called on _event_, it returns [`container`, shadow root].

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1098#issuecomment-2803514331
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/1098/2803514331@github.com>

Received on Tuesday, 15 April 2025 01:43:11 UTC