Tagged “standards”
Use the dialog element (reasonably), by Scott O’Hara
Here’s an important update on native modal dialogues. TL;DR – it’s now OK to use dialog
.
Last year I posted that Safari now supported the HTML dialog
element meaning that we were within touching distance of being able to adopt it with confidence. My caveat was:
However first I think we’d need to make an informed decision regarding our satisfaction with support, based on the updated advice in Scott O’Hara’s article Having an Open Dialog.
(Accessibility expert Scott O’Hara has been diligently testing the dialog
element for years.)
However the happy day has arrived. The other day Scott posted Use the dialog element (reasonably). It includes this advice:
I personally think it’s time to move away from using custom dialogs, and to use the
dialog
element instead.
That’s an important green-light!
And this of course means that we can stop DIYing modal dialogues from div
s plus super-complicated scripting and custom ARIA, and instead let a native HTML element do most of the heavy lifting for us.
From a Design System perspective, I’d previously suggested to my team that when we revisit our Modal component we should err toward a good custom dialogue library first, however I’m now likely to recommend we go for native dialog
instead. Which is great!
Refactoring a modal dialogue in 2022
My team will soon be refactoring our modal dialogue component. Ours has a few deficiencies, needs better developer experience and documentation, is not built to our Design System component standards, and could use a resilience boost from some progressive enhancement.
For a long time the best – meaning accessible, framework-agnostic, feature-packed – modal implementations were custom. Specifically:
However with recent browser advances (especially from Safari), there’s an argument that the time has now come that we no longer need custom solutions and can go native. So we might reach for the native <dialog>
HTML element.
However first I think we’d need to make an informed decision regarding our satisfaction with support, based on the updated advice in Scott O’Hara’s article Having an Open Dialog.
Additionally we should definitely be keeping one eye on proposals around the exciting new togglepopup
and popup
attributes which promise the holy grail of entirely HTML-powered modal dialogues with no JavaScript dependency.
Accessible modal dialogues in 2019
I previously noted Keith J Grant’s article on the HTML dialog
element which promised a native means of handling popups and modal dialogues. I’ve not yet used dialog
in production, partly because of spotty browser support (although there is a polyfill) but also partly because—for reasons I couldn’t quite put my finger on after reading the spec—it just didn’t feel like the finished article.
Fast forward to March 2019 and Scott O’Hara has written an excellent piece describing why it’s still not ready. There are a combination of factors: lack of browser support, reliance on JavaScript; and multiple accessibility issues.
The good news is: having dug deeper into Scott’s work I see that among the many accessible components he has shared with the world is a custom, accessible modal dialogue. So next time the need arises, I think I’ll start there.
Thanks, Scott!
See all tags.