-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
API to get top layer elements #9075
Comments
This is an interesting suggestion, but the bar for adding an API is higher. We don't add public API surface just for tests either, for instance. cc @nt1m |
I'm rather opposed to this, I think something being in the top layer or not should remain an implementation detail of the individual APIs using it. |
@nt1m to clarify a bit further, my thinking is that if browsers are (or will be soon) allowing ways to inspect the top layer and the order of the elements in the top layer, it would be great to have a way to get that same data with something like |
I could see non-test use cases also, such as a popover component wanting to make sure it's topmost, and if not, closing and re-showing the popover to put it on top. You wouldn't want to do that unless you knew it was necessary, to avoid flickering and starting animations and such. One constraint that I think should be a hard constraint, if we add such an API: don't reveal elements in the top layer. You can instead "ask" whether one top layer element is above another, such as: element1.isAboveInTopLayer(element2); so that you'd have to already have references to |
This is exactly the use case I was looking to solve when I found my way here. Ideally a toast container should be able to listen for a top-layer event on the document, check to see if it is still at the topmost layer and do some action depending on the result. |
Something that would perhaps be a bit more consistent with existing APIs would be something like Would that help with the use case above? Or is there something that really needs "all the elements in the top layer, in order"? We fire popover |
Dialog doesn't fire toggle events (see #9733) but you can observe the |
Beautiful! I just used this in one of my PlayWright tests: // Check if the dialog is in the top layer
expect(await page.locator('dialog[open]').evaluate(el => el.matches(':modal'))).toBe(true); |
The OddBird team is currently building a polyfill for CSS anchor positioning.
To support anchoring top layer elements to each other, it would be very helpful to have a programmatic way to get the order of the elements in the top layer set. This is particularly useful to prevent a top layer target element from anchoring to a succeeding top layer anchor element. See this WPT for an example.
This issue is similar to #8783 but we're interested in all the elements of the top layer set to access their order.
cc: @jgerigmeyer @mfreed7
The text was updated successfully, but these errors were encountered: