RSS FeedTwitterMastodonBlueskyShare IconHeart IconGithub IconArrow IconClock IconGUI Challenges IconHome IconNote IconBlog IconCSS IconJS IconHTML IconShows IconOpen Source Software IconSpeaking IconTools IconShuffle IconNext IconPrevious IconCalendar IconCalendar Edit IconNotebook IconObservable Notebooks IconSlash IconGoogle G Icon
5th element buzz off scene
A cartoon skull with a hotpink hat on.2 min read

closedBy=any

html

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:

dialog.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!

8 comments #

25likes
9reposts
  • Bundyo
  • tkdn
  • Silvestar Bistrović
  • Fynn Ellie Be
  • Schalk Neethling
  • Felix
  • Tab Atkins-Bittner
  • Thomas Steiner :chrome:
  • westbrook

Join the conversation on

COOL ????
Sindre BøyumSindre Bøyum

@argyleink Agreed. Just included it in the progressive enhancement course I'm writing ;-)

Aaron GustafsonAaron Gustafson
About damn time!
BrewedCodeBrewedCode

@argyleink Another cool thing to add on my todo list ????????

FelixFelix
Been using it recently. And found an excellent, easy to use polyfill for browsers that don't support it github.com/tak-dcxi/dia...
iamallyniamiamallyniam

@argyleink hey @jensimmons I’d LOVE to see this added to Safari ????

Wenzel ????‍????Wenzel ????‍????
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øllerAndreas Møller