-
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
Support popovertarget
on custom elements with role="button"
#9110
Comments
It is not just /cc @scottaohara @mfreed7 who can probably reference exact discussions on this. |
@keithamus just checking but what about custom elements? Do they work as well as long as the have |
Elements with a You can use the imperative API of |
This sucks for design systems using custom elements. For example: <sl-button popovertarget="popover">Toggle popover</sl-button>
<sl-popover id="popover">I'm a popover</sl-popover> So this scenario would not work. Is there a good reason why this couldn't work? |
popoverTargetElement
on non <button>
elementspopovertarget
on custom elements with role="button"
An element like openui/open-ui#302 goes in to some of the reasons behind the design especially in relation to custom elements, and may be worth a read:
(BTW this needs label
topic: popover
|
Even though custom elements are a JS API, if I can I would much rather implement things declaratively. So I'm not saying I can't make things work using the current spec (I can using the So nothing is blocking me from doing it imperatively, but the DX of doing it declaratively is much better. So is there any specific reason why custom elements with |
Yeah FWIW I'm not suggesting it couldn't (or even wouldn't) be supported but I'm explaining the current rationale. Currently |
This is yet again another great reason to native behavior mixins to be surfaced to custom element authors (and in a declarative way). I know that's a whole other spec space, but we can't add new features like this if at ever turn we're going to be doing so without conscious awareness for the many related parts of the spec. Some might say |
Sorry if it's a dumb question, so in order to use popover api in the Declarative shadow dom, we have to use js? |
In order to use the popover API cross-root, you will need to use JS. If the popover API is used entirely in light DOM, or entirely within a shadow root, then it will work fine. So the following examples work fine: <my-element>
<template shadowrootmode="open">
<button popovertarget="my-popover">Open</button>
<div popover id="my-popover"></div>
</template>
</my-element> <my-element>
<button popovertarget="my-popover">Open</button>
<div popover id="my-popover"></div>
</my-element> It is not possible to do this: <my-element>
<template shadowrootmode="open">
<button popovertarget="my-popover">Open</button>
</template>
<div popover id="my-popover"></div>
</my-element> Instead it requires JavaScript to assign the element cross root: <my-element>
<template shadowrootmode="open">
<button popovertarget="my-popover">Open</button>
</template>
<div popover id="my-popover"></div>
<script>
class MyElement extends HTMLElement {
static {
customElements.define('my-element', this)
}
connectedCallback() {
this.shadowRoot.querySelector('button').popoverTargetElement = this.querySelector('#my-popover')
}
}
</script>
</my-element> The |
Wow thank you for the detailed reply!! |
We should make this work for custom element submit buttons, which don't exist yet: WICG/webcomponents#814. And maybe there should be a way to say that a custom element is a plain button as well. |
@annevk it would be great for there to be a way for a custom element to (say that it is a button and) participate in this API. 👏🏼 👏🏼 👏🏼 If |
So https://open-ui.org/components/selectmenu/#default-behavior has something like this: <button behavior="button">Open</button> "The behavior="button" attribute on the inner tells the browser that this element is what we want to use as the new button. The browser will automatically apply all the click and keyboard handling behavior to this element as well as the appropriate accessibility semantics." This seems selectmenu specific, but I kind of like it for custom elements: |
I wonder if flipping customised built in elements on their head would be useful? |
I think we should take the approach suggested for submit buttons and generalize it a tiny bit so it can be used for both buttons and submit buttons. I.e., something like |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Big +1 to this idea I think it's worth taking a step back when thinking about it because there's lots of possible options, like is there a way to ask for the default styling of the button?, would setting it to a button make it focusable automatically?, should these instead be separated out (focusability is useful for other more generic types of UI). |
As |
We briefly discussed a solution that could work for this in the hack week discussion on AOM reference targets. @lukewarlow or @alice might be able to say more but I think with a combination of inward/outward targets things like popovertarget should be able to work in combination with shadowroots |
Cross-shadow root is one thing, I mean a big thing! However, if |
I'd rather make invokers/commands/actions global and let one to use those. The popover specific attributes could be deprecated. |
It doesn't seem like a great idea to globally hijack the default activation behavior? Allowing custom elements to opt into it seems preferable. |
If I read the spec correctly, then
popoverTargetElement
will returnnull
unless the node is a<button>
?That seems quite limited and incorrect?
See https://html.spec.whatwg.org/multipage/popover.html#the-popover-target-attributes
Edited: changed the title to better reflect the issue. This basically forces design systems to implement the
popovertarget
behavior themselves. Or work around it by adding a<button popovertarget="...">
to the light DOM.The text was updated successfully, but these errors were encountered: