-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
popovertarget
and shadow DOM
#9109
Comments
Trying to make sure this isn't lost in the noise: cc @jakearchibald |
There already exists an imperative API for cross root bindings. To extend your example with functioning code: <button popovertarget="foo" popovertargetaction="show">
Show a popover
</button>
<my-article popover=auto id="foo">
<template shadowrootmode="open">
This is a popover article!
<button popovertargetaction="close">Close</button>
</template>
</my-article> class MyArticle extends HTMLElement {
static {
customElements.define('my-article', this)
}
connectedCallback() {
this.shadowRoot.querySelector('button').popoverTargetElement = this
}
} |
Refs openui/open-ui#651 |
@keithamus Thanks; I was kind of hoping I wouldn't need to write JS for this, but fair enough. |
There does need to be an declarative API, at some point. Would be best to push on this early, and set a standard for other specs whereby this detail isn't left out of proposals in the future. There are some similar concepts going around within the AOM for cross root aria, maybe room to align techniques? |
Needs label
topic: popover
|
There is also the opposite case where the popover is in the shadow DOM and the button in the light DOM should invoke it: https://codepen.io/tuelsch/pen/LYMvmva <test-popup>hello, this is a test</test-popup>
<button popovertarget="testpopup">this should cross shadow boundaries and trigger a popup</button> const template = document.createElement("template");
template.innerHTML = `
<div popover id="testpopup">
<slot></slot>
</div>
`;
class TestPopup extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({ mode: "open" });
this._shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define("test-popup", TestPopup); Not sure if this use-case should be handled as well. |
I've recently come across the limitations with this cross-root popover API, it would be very nice if you could use the IDL to assign elements truly cross root. e.g. button in light dom, popover in shadow or button in shadow, popover in shadow. If you have the element reference you already have full access to the shadow tree so I don't think this would expose anything you don't already have? |
Assigning ID references across root without having full access to the child root is proposed to work along these lines. Things like However, something fully declarative here would be quite nice and should likely be a requirement, at some point. |
So in this example from https://html.spec.whatwg.org/multipage/popover.html#the-popover-target-attributes
The close button will not work if
<article>
is a custom element instead. This is a pretty common thing with shadow DOM:id
s are scoped to the shadow root.It would be awesome though if the example above could work with custom elements.
Perhaps add
popovertarget=":host"
to the spec?The text was updated successfully, but these errors were encountered: