The top layer: a solution to z-index:10000
developer.chrome.com
developer.chrome.com
But we've heard your feedback, and today, in 2023, we bring you the "topper-layer", accessed using z-index:12000.
You might be wondering if we're going to stop here. The answer of course, is no. We have a roll-out plan for the next 8 years which will culminate in z-index:100000.
Some of you might be asking if our plans for the super-topper-most-mostest-layer are really just reducing this all back to "normal" z-index stacking in the document flow. We'll leave that as a discussion for the forums, while we get back to work."
So. Many. Footguns.
There really is almost no case in which a combination of DOM hierarchy and positioning isn't sufficient.
This is not the point though. If I understand correctly, the "top layer" allows positioning elements on the z-axis independent of the parent stacking context. So kind of like absolute positioning on the z-axis.
z-index: 10000 is not something you actually need, it is typically the result of someone desperately trying to stack an element over another in a different stacking context. Stacking context are not always well understood, and most developers would intuitively expect an element with z-index 8 to cover an element with z-index 7. But this is only the case inside the same stacking context, not if they are in different subtrees.
The use cases for breaking out of the stacking context is where something like "portals" in React is used: https://reactjs.org/docs/portals.html
> A typical use case for portals is when a parent component has an overflow: hidden or z-index style, but you need the child to visually “break out” of its container. For example, dialogs, hovercards, and tooltips.
But portals are a complex hack, where "top layer" allows you to keep the logical document structure.
If there’s value here I can’t see it from their blog post and demos.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogE...
Think of the "top layer" as similar to inserting an element as the last child of the document body. This is how modals and overlays are usually implemented - by inserting the element last (and position it absolutely) it will automatically stack higher than anything else in the document. At least until something else is inserted last.
Z-index is actually not that useful for stacking elements (whether in top layer or not) since it only works inside the scope of a stacking context. Element order is a better way to control stacking.
Example:
<year dropdown> over <date picker> over <modal form> over <desktop style app>
A complex “desktop style” UI, that shows a modal form over it, and the modal form contains a custom date input component. Click the date input and a custom date entry pop up component is drawn above the modal form to pick the date. On the custom date entry pop up is a year picker, which you click and a custom year dropdown is shown. This was an actual example from my past (I’m not saying it couldn’t have been done better, but this was before there were many better ways to do it). Using absolute z-index required complex coordination between components.The top-layer at least solves the problem of covering the viewport and providing a backdrop (difficult to do reliably, especially 10 years ago). Although I can think of other issues one still needs to solve: disabling inputs and events behind “modal” pop up, disabling iPad background scrolling, must be accessibility, can need multiple layers of popups e.g. loading spinner, problem of tab key handling, et cetera.
It's not exactly what you asked for, but it does void the need to coordinate between too many components.
Who would have thought that `will-change: mask-image` would have similar effect similar to `position: relative`?
If you want exactly that, and only that, my conclusion is that the best way is to use `isolation: isolate`.
The other issue it doesn't have is if you specify "A over B and B over A".
https://en.wikipedia.org/wiki/Topological_sorting#Uniqueness
z-index: 999 !important; top-layer: 999 !important; -webKit-actually-paint-me-last: true !inportant;
2. There should be a webext-exclusive API for placing items above the top layer.
> And it’ll try something nastier, like enumerating all the processes on the system, attaching to each one with debug privilege, and suspending all the threads.
This is like playing corewars with Windows desktop software :)
> “Note to self: Do not get into a walls-and-ladders contest with Raymond.”
Don't play with the person who knows all the lower levels :)
Moreover, Windows literally added support for the "even more topmost" feature later - they're called "bands", and supported by CreateWindowInBand(), except IIRC Microsoft later restricted support for that function to its own signed binaries, presumably to prevent vendors from abusing it. Needless to say, the addition of that function didn't violate the accepted rules of metaphysics.
but that's what those blogposts were about! The customer wanted their window to be on top of every other window - even if the other window is asking to be on top of every other window!
If you have a secret "super-duper-topmost" window flag, then you're not really satisfying the customer's request. but if you do indeed have this super-duper-topmost window flag, what happens if two windows tried to ask for the same? How do you decide which goes ultimately on top?
If what you say is true, the only way they prevented that is by not making the new super topmost accessible to users, which isn’t really fulfilling the users request.
There should be a webext-exclusive API for placing items above the top layer.
Together with a priority in extension settings.
And then maybe next year they will propose a new syntax for setting z-index to epsilon zero.
Popups have existed on the web for ages. This just proves a more convenient syntax without having to inject dom elements at the end of the body element (which is how popups are traditionally done).
Well, since I control the whole content and know there's no dialog or anything else like that on my blog I could put it in toplevel, but what if I had? What if multiple stacked dialogs were to be opened (Win 3.1 style)? Is it possible to order things inside this toplevel? Maybe using z-index?
In any case, I'm just discovering this but it seems to be more about having a container with specific positioning than just replacing z-index (which is merely a consequence of that container loving outside of the <html> object). Also makes me want to have a bottom-level as well (e.g implementing cool effects on the background, think X11 root window).
Except … we were practicing a section of a piece. And then we started digging into the details on a very specific portion of footwork in the middle of that section. And our choreographer, instead of saying "start from the section", said, "start from the top". And humans being what they are, we all understood, somehow, and the right thing was done without complaint.
But then came the need to start from the beginning, at which point she now had to differentiate from what she had been calling (erroneously) "top", and uttered "start from the top top". Some amount of playful joshing followed … and then the term stuck.
They're not only monopolistic, they abuse that monopoly power often just because they can, in a careless way that only the obscenely powerful can do.
That has soured people's opinion of them. Long gone are the days of "Do no evil" in their mission statement. Now evil is just a casual stepping stone on the path of squeezing out every eyeball-second from the products.. err.. I mean "customers".
Even if they were talking about removing dialog entirely https://twitter.com/voxpelli/status/1423207772498415616 (and none of the issues with dialog have been resolved since)
So this top layer bullshit is just a hack to make another hack work. It's not a usable long-term solution, and expect more hacks to deal with this hack in the future.
Is this just a new way the browser displays the <dialog> element exclusively? I'm pretty confused.
The CSS2.1 spec [1] describes how stacking contexts work when painting the browser window. Traditionally, our mechanism for interacting with an element's stacking context has been more or less exclusively to set its z-index.
The Fullscreen API spec [2] introduces a new stacking context called the "top layer", which has some unique properties. Most notably, things rendered in the "top layer" are always rendered on top of everything else, regardless of z-index. There is exactly one top layer per document.
Parts of this spec also describe operations which can add and remove elements from the top layer. For example, the "fullscreen an element" operation adds it to the document's top layer. [3] This operation is invoked as part of the steps taken when a developer calls `requestFullscreen()` on a DOM element [4].
Now, the `<dialog>` element as specified in the latest HTML spec [5] also interacts with the page's top layer. When you call `.showModal()` on a dialog element, it gets added to the document's top layer. Note that although this is a completely different API, the commonality here is that we're also interacting with the top layer by adding and removing elements from it.
The article also references some ongoing discussion [6] on a possible "popup" API which would also interact with the top layer, and which would be used for implementing various controls such as datepickers and dropdown lists.
Hope that helps!
1: https://www.w3.org/TR/CSS2/zindex.html
2: https://fullscreen.spec.whatwg.org/
3: https://fullscreen.spec.whatwg.org/#fullscreen-an-element
4: https://developer.mozilla.org/en-US/docs/Web/API/Element/req...
5: https://html.spec.whatwg.org/multipage/interactive-elements....
Sounds like an attribute does the actual promoting.
"outside of the document flow": that can't be clearer. It's almost imprudent.
Problematic UI use cases:
- z-index is a hint, the real layering depends on the positioning of the parent element. The usual trick is to insert an element at the bottom of the DOM, and then use z-index.
- If you create a Dropdown or a popup UI (eg. a date picker), the accessibility of focus handling is hard. Your component needs to appear in a top-layer but by inserting it in a div at the bottom, you loose the tab order that goes from the trigger button to the popup. (there is an aria attribute to associate the control, but at least VoiceOver ignores it, and the browser doesn't respect the tab-order).
- The dialog element not only solves the positioning on top, it also solves the focus-trap that is needed for a keyboard navigable (accesible) UI.
- It's possible to use dialog for a non-modal popup. However, the specs doesn't say much about layering. (in fact a quick dialog test in Chrome/Firefox/Safari... they don't follow a predictable layer positioning).
The thing is, if you need to create a dialog, tooltip, dropdown, or popup today... you need a lot of hacks.
This top layer isn't a solution either. It's still a hack
This top-layer feature only solves the element at the bottom + positioning + z-index hack.
I wish to have a sort of programmatic stack API. But, the constraint of using HTML makes these things messy. The stack is implicit by nesting dialogs, and dialogs can be modeles, but is not a proper API for pop ups. (the article points to a pop up proposal, but my expectations are low)
I can change my modals to top layer, okay. What happens to my dropdowns that can be used both inside the modals and under the modals then?
Oh it's a feature of the <dialog> element I guess
Just set ”position: relative” on an element and it will start a new stacking context, and stack it within the underlying context. It’s like having a card in a card stack be another stack of cards.
A truly FOSS Chromium team, or a revitalized Firefox team would be better for managing rendering engines and specs. Maybe just taking the big guys out of the specs would be a good start.
It's so funny to me how transparently contrarian the entire Vue community is.
No no, they're totally not React Portals which have existed for 5 years... they're Vue Teleports!
[1] http://web.archive.org/web/20160604042509/http://www.puidoka... [2] https://codepen.io/myf/pen/QWmRZEJ?editors=0011 (2147483647)