-
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
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. |
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: