-
Notifications
You must be signed in to change notification settings - Fork 312
[DRAFT] Propagate events into the event's source's tree where appropriate. #1377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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> |
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