[DRAFT] Propagate events into the event's source's tree where appropriate.#1377
[DRAFT] Propagate events into the event's source's tree where appropriate.#1377alice wants to merge 1 commit into
Conversation
- Add the concept of a "source" for an Event. - Modify shadow root's "get the parent" algorithm such that events propagate into the event's source's tree where appropriate.
|
This concept of re-despatching on the host might have confusing consequences for developers, who will be able to observe events pointed at a target that would commonly dispatch those events, but weren't the source of this event. For example: <button id=b>Hover me</button>
<div id=popoverA popover>
<template shadowrootmode=open>
<div id=popoverB popover>
</div>
</template>
</div>
<script>
let popoverB = popoverA.shadowRoot.querySelector('#popoverB');
b.addEventListener('mouseover', () => {
popoverB.showPopover({source:b});
});
b.addEventListener('mouseout', () => {
popoverB.hidePopover({source:b});
});
</script>AIUI, In this example, when popoverB is shown it will dispatch a This feels like it could make it extremely difficult for developers to ascertain when an event has been dispatched because a host element has/is changed/changing state, or whether one of its shadow descendants happened to do change state and the I think for this to move forward it would probably need some kind of additional property on Events, like |
|
@jakearchibald Any thoughts? I would note only that the same is presumably true for |
|
@keithamus just paging some of this back in… Am I right that this isn't really a problem with reference targets, since that creates a deliberate link between the shadow root and the host? |
|
This might be a problem with reference targets if |
|
AIUI
<button id=b popoverTarget=popoverA>Click me</button>
<!-- even though popoverA has the popover attribute, b refers to popoverB -->
<div id=popoverA popover>
<template shadowrootmode=open shadowRootReferenceTarget=popoverB>
<div id=popoverB popover> <!-- an event fired here appears to come from popoverA -->
</div>
</template>
</div> |
|
I did run into a variation of the issue that @keithamus raised here when updating some reference target tests to account for the new event propagation behavior. I worked around it by checking This doesn't work for closed shadows though. But I'm not convinced this will be a problem for real-world use cases; the test cases are pretty contrived. It seems like a adding a boolean exposing this information even for closed shadows would be an easy backwards-compatible addition if it did turn out to be a something developers run into problems with for closed shadows. |
|
I'd like to get this reviewed together with the main reference target spec in preparation for potentially shipping in Chromium, so I pulled it into #1353, and pulled whatwg/html#11349 into whatwg/html#10995. @alice let me know if you'd prefer to keep driving it separately and I can back it out. |
When an event is triggered by a source in a different tree from the target, propagate events into the source's tree
(where appropriate) so that event listeners can be added in that tree without needing to have access into the
target's tree.
whatwg/html#11349 pulls the event source concept into the HTML spec.
See WICG/webcomponents#1098 for more information and worked examples.
Preview | Diff