closedBy=any · October 16, 2025
Adam Argyle
·
2025-10-16
·
via Starred Articles
Quick post on closedBy="any", a declarative way to add light-dismiss to a dialog:
<dialog closedBy="any">
<p>Hi, I'm a dialog.</p>
</dialog>
And just like that, tapping or clicking outside the dialog will close it.
Oh yeah! Well I bet I can't use it yet.
#
Here's the browser support:
Or a bit-o-js to get you started:
someDialog.addEventListener('click', ({target:dialog}) => {
if (dialog.nodeName === 'DIALOG')
dialog.close('dismiss')
})
More resources
#
You should write one!
I'm writing this because I haven't seen enough folks using it or talking about it. Pretty nifty feature if ya ask me. So I'll make a 10m post.
If you want more <dialog> goodness, I wrote a fun post about how to make nice dialogs cuz the defaults are so poopy. Check it out and have a dialog.
Also checkout the Dialog Starter notebook!
10 comments
@argyleink Agreed. Just included it in the progressive enhancement course I'm writing ;-)
Aaron Gustafson
@argyleink Another cool thing to add on my todo list ????????
Felix
There should be a viewer discretion notice before showing variable shadowing like this.
dialog.addEventListener('click', ({target:dialog}) => {
if (dialog.nodeName === 'DIALOG')
dialog.close('dismiss')
})
Andreas Møller
I was trying to look into how you did that pwa install banner, to see if you meant to be using dvh instead of vh or something, as it stays floating when url bar hides when I scroll (I have url bar at bottom), but I couldn't find anything. Is that a chrome native thingy?
Carl Vuorinen
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。