惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
P
Privacy & Cybersecurity Law Blog
H
Help Net Security
云风的 BLOG
云风的 BLOG
G
GRAHAM CLULEY
Spread Privacy
Spread Privacy
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
P
Privacy International News Feed
Blog — PlanetScale
Blog — PlanetScale
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
The Register - Security
The Register - Security
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
PCI Perspectives
PCI Perspectives
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
A
About on SuperTechFans
W
WeLiveSecurity
GbyAI
GbyAI
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Check Point Blog
Y
Y Combinator Blog
月光博客
月光博客
Scott Helme
Scott Helme
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
U
Unit 42
G
Google Developers Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google Online Security Blog
Google Online Security Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 司徒正美

Ben Frain

So, you want a React modal that uses the <dialog> element and transitions in AND out? Scroll indicators on tables with background colours using animation-timeline Review: SoundPEATS Clip1 Open ear clip-on headphones VS Code – highlight just the active indent guide Review: MoErgo Go60, a split ergonomic and fully programmable keyboard Review: Kinesis mWave mechanical ergonomic and programmable keyboard iOS26 Safari theme-color/tab-tinting with fixed position elements is a mess New Book: Responsive Web Design with HTML5 and CSS, 5th Edition Use @supports with a proxy feature/value for features you can’t test for (@starting-style) First adventures in View Transitions Review: Benq Screenbar Pro and Halo lightbars. The kit you never knew you needed! Center items in a container, and make then left aligned when they overflow A single element CSS donut timer/countdown timer, that can sit on any background Review: Open Ear Headphones – Bose Open Ultra v Huawei FreeClip In search of the perfect autocomplete for CSS Managing multiple versions of node, without NVM or additional tools Review: Keychron Q14 Max Alice 96 Key mechanical keyboard NEW VIDEO COURSE: Responsive Web Design with HTML5 and CSS Is CSS Grid really slower than Flexbox? Review: Advantage360 Pro Signature Edition 2024 mechanical ergonomic keyboard More Keys or Fewer Keys for mechanical keyboards Yes! You can use position: sticky and overflow together Neovim – how to do project-wide find and replace? Review: Keyboardio Model 100, split, wooden, mechanical keyboard Struggling to learn SwiftUI How to create rounded gradient borders with any background in CSS How to get equal size icons in the cmp completion menu of Neovim with Kitty terminal Review: Dygma Defy, split, mechanical, programmable ergonomic keyboard What’s the best way to reset WAAPI chained animations? Using CSS @property inside shadowRoot (web components) workaround Dynamically create a ref for items when iterating over them in lit.dev templates Selecting and pausing running animations in Lit Web Components Review: ZSA Voyager, split, mechanical keyboard Russel Brand, narcissism, and a sadly common pattern… When it comes to text editors, I feel like Goldilocks Simple settings for writing and converting markdown with Sublime Text Review: The ZSA Platform tenting kit for the Moonlander keyboard Logitech MX Master 3/3s scroll wheel fix Building a line graph with CSS clip-mask Review: Dell 6K 32″ Monitor U3224KBA I broke my keyboard! Swapping the key switches in the Kinesis Advantage360 Pro HUGE macOS Productivity boost: Set-up simple, keyboard only, instant App switching and arrangement Adding to $PATH for a central location for Neovim/NPM tools Neovim Power Tips: Volume 2 Review: MoErgo Glove80, split, wireless, columnar ergonomic keyboard with RGB Review: Kinesis Advantage 360 Pro — split ergo mechanical keyboard Review: Dactyl Manuform – an ergonomic, custom built mechanical keyboard How to animate along an SVG path at the same time the path animates? Getting the context of Web Components (lit)
New Web APIs — a popover on top of a dialog element can’t be interacted with?
Ben Frain · 2023-11-15 · via Ben Frain

Update 20.11.23 — the current behaviour of not being able to interact with a popover above a modal dialog is ‘as spec’ but could maybe be tweaked. I opened an issue at the CSS Working Group issues here, so add your thoughts: https://github.com/whatwg/html/issues/9936#issuecomment-1818385368

Imagine an interface. In it, there is a button. You click the button and we launch a new piece of UI over the top of everything. You stay in that ‘upper’ UI until you are done and then dismiss this UI to return whence you came down below.

Got that? Great. How would we build that?

Launching something above everything else for some temporary period of time seemed a perfect use case for the dialog element.

OK, my understanding of dialog elements and the top layer at this point…

When you use showModal() the dialog in question is promoted to the ‘top layer’. This lives beyond the normal document confines, allowing the contents of the dialog to live above the DOM. The resultant dialog, when using showModal() is positioned with fixed layout by default and a bunch of user styles. Crucially it also comes with a ::backdrop pseudo element, which, although you can use inset: unset; to allow you to move it around, and even though you might stick display: none on that backdrop pseudo element, the DOM below remains inert as if the backdrop were there anyway.

So, for our ‘upper’ UI, dialog seems a good fit.

But then what when you need to position something on top of that modal dialog?

Crucially, this extra item isn’t full screen, so doesn’t warrant showModal() itself. Well, you might think you could use show() on another sibling dialog instead?

You cannot.

Well, you can, but using show() does not promote this new ‘top’ dialog to the Holy Landtop layer. And as z-index has no powers in or over the top layer, using z-index is a dead-end, it simply won’t work — seriously, it is futile, OK? With show() your dialog is shown, but below the lofty heights of the top layer.

‘Screw this’ you think (I sure did), let’s just make this second upper dialog use showModal() too. That way, if I put it after the first dialog in the DOM, it will surely appear on top?

Yes, but… no.

It appears on top, but have you not been paying attention? Because it is in modal mode, it has a backdrop that even when you kill it off with display: none;, is un-killable like some Freddie Kruger style nightmare pseudo element. Somehow, the contents below this upper dialog remains dead and inert to you.

You can look at this approach here.

So, is that it? Defeat? Are those dev rels touting this months ‘hot new shizzle’ just full of baloney? Is it back to standard elements and good old z-index: 1000?

Not on your nelly pal, we got one last thing to try: popovers.

Even newer than the newish dialog element is the popover API, which at first glance looks like it might be just the ticket.

The Popover API provides developers with a standard, consistent, flexible mechanism for displaying popover content on top of other page content.

Popover API to the rescue?

So, I refactored things a little, changed the second dialog element to a div with the popover attribute. And then rewired the JS to show and hide the new fangled popover instead:

launchTop.addEventListener("click", () => {
  if (isTopShowing) {
    isTopShowing = false;
    topDog.hidePopover();
  } else {
    isTopShowing = true;
    topDog.showPopover();
  }
});

You can look at his one here.

At first I was elated. I launched the first dialog in modal mode, and I then clicked the button to launch the popover from the modal and there it was, the popover. I clicked the button on the original modal again and it disappeared. Wow, fantastic, love these new APIs (narrator: “little did he know, he was soon to be swearing at these new APIs”).

That it? Kiss the dame and roll credits? Sadly, this story doesn’t have a happy ending (yet?).

Here is the kicker. You can’t do anything with the contents of this popover when it is sat on top of a modal dialog. Even though you can see the popup, you cannot interact with it. Try clicking the ‘Close Me’ in that example.

However, as soon as you close that dialog, so that you are left with the bottom UI and the popover, you can now interact with the popover as you might expect.

The end

And so here I end this tale of woe, hoping the entirely probable likelihood exists, that I am merely “doing it wrong”. Please, someone, enlighten me.

On the face of it, and admittedly coming at this from a position of rushed naivety, this seems ‘broken’. All this ‘top layer’ stuff is all well and good, but can someone explain, how one has something in a top layer, and then another item above that, that can actually be interacted with?

As ever I’m expected to be schooled on the right way to do this. For now I opened a bug report for Chromium

If it can’t, then there are going to be an awful lot more devs that will continue opting for good ol’ divs and z-index: 1000.