-
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
Feature Request: Top Layer Stack Management #10370
Comments
Another workaround I’ve seen authors do is the creation of predefined swimlanes (or layers) of empty divs with To show something in the top layer, instead of triggering I don’t think this workaround is very practical to work and kinda defeats the whole purpose. A practical use case where an author used this was to keep tooltips visible on top of toasts, while keeping the toasts on top of a dialog that gets shown later in the page’s lifetime. |
An aspect I missed, thanks to @lcoronelp for pointing it out, is that non-modal items moved above a modal dialog will still be inert even if visually they are on top. See https://jsfiddle.net/link2twenty/75xnL2ap/ For toast specifically this can be an issue if the toast contains a call to action or a dismiss button. A solution would be to not open any modals and handle inert manually, though this feels prone to accident. |
This is tracked in #9075. |
I don't believe #9075 lines up exactly with what I'm trying to solve, though does cover part. API to get top layer elements
Top Layer Stack Management
What is the correct protocol here? Should I make more specific issues with no overlap, take my comments over to 9075 or just perhaps I've misunderstood and all the comments are covered? |
What part do you think is not covered? Pretty sure it touches on all of that (though not all in OP). |
I've just reread the other issue, maybe I'm missing something but it doesn't seem to have;
|
If you’re able to, you can insert those elements within the modal dialog which will ensure they’re not inert and they’ll layer correctly. |
I considered doing this but it means we'd have to render the elements both inside and outside the modal dialog, so they appear even when the modal dialog is closed. It gets even more complicated when you consider that we have nested modal dialogs, so we'd have to render them inside there as well! 🤯 |
I have the beginning of a musing https://codesandbox.io/p/sandbox/modal-change-xpskc7 still feels a little hacky but perhaps may help. The basic premise is to use a MutationObserver to listen for attribute changes over the entire body, we're listening for the I know this example is in React but I'm fairly certain it would be quite easy to implement in vanilla using Again I'd feel much happier with an event on the window or the ability to watch for mutations in the top layer specifically. |
This is the symptom that this api, is insufficient, we need the ability to control what element should show on top similarly to how we do it with The modal element cannot arbitrarily decide to go on top of everything else. It can be z-index or it can be the order of the element in the DOM hierarchy, but we really need a way to control this. |
It's a shame this was closed in favour of #9075 because I feel like there should be a declarative way to control the order of top layer elements—something that doesn't require JavaScript. Especially given the direction I believe we're heading where popovers and modal dialogs won't require JavaScript. I'm thinking something like |
I've recently been experimenting with writing a library that would allow extensions to more reliably draw on top of page content. This is a common pattern used by extensions such as Omni - modals are very promising in this context but there are still pain points. If an extension is showing a modal in the top-layer, there are two approaches it can use to ensure this stays on top of any website content:
Similarly, there are cases where extensions may want to show a toast or autocomplete UI on top of a website modal. A popover seems like the right approach here. However, this has the same problems @OliverJAsh mentioned:
An idiomatic way to solve these problems would likely allow us to fix some of these shortcomings. In extensions, there are other ways we could solve these problems - ensuring elements added to the top-layer by an extension always remain on top, or adding an extension specific API as discussed in w3c/webextensions#347. However, I would much prefer to solve these problems on the web and in a way that reduces how often extensions have to interfere with the DOM. |
As I see it, there are two ways we can move forward to solve these issues: JavaScript Approach#9075 is a great start, but to use it effectively, we’d still need:
These additions would allow dynamic reordering and event-driven tracking of the top layer. HTML & CSS Approach (No JavaScript Required)If we want a more declarative way to handle this, we could propose:
Shared RequirementFor either approach, we'd need a change to the current Would it be best to split these into three separate issues (JS API, CSS, and |
A reasoning against this I often hear is that it would be That said, I personally think having three options for However, like you mention, that would not prevent toast notifications being inert when a EDIT: I hacked something together with your top layer observer and |
What problem are you trying to solve?
Inconsistent Stacking: Right now, elements in the top layer are added on top of each other based solely on the order they are added. This can cause issues for UI elements that need to stay on top, such as toast notifications or live chat. A new element added later might unintentionally cover them.
What solutions exist today?
Manual Removal and Re-addition: A developer can remove the element they want on top from the top layer temporarily using JavaScript. Then, after adding the new item, they can re-add the desired item back to the top layer. There currently is no way to detect items being added to the top layer stack you must track this yourself as you promote items.
This manual tracking will become impractical as more and more libraries use top layer (via popover and dialog).
How would you solve it?
We'd need a few things added to be able to do this nicely,
window
,document
orbody
unless a newwindow.topLayer
property was added.window.topLayer
property.element.sendToTop()
orwindow.topLayer.bringToTop(element)
.I think the first two points can be solved by making
window.topLayer
return anElement
that can be observed with a mutation observer. I'm not sure how practical this approach would be but here is a snippet of how I'd imagine it working.Anything else?
Whilst this is not a major issue, I'm sure it will start being a thorn in the side of developers as
popover
anddialog
become more prevalent.This issue is on the toastify and shows that it is already becoming something noticed by the community (even if slowly).
Also here is an exchange I had on twitter/x with @bramus looking for an existing solution.
The text was updated successfully, but these errors were encountered: