Modals used to mean a pile of JavaScript for focus, the Escape key, and stacking. The dialog element and the Popover API now handle most of that for us. Our new tutorial shows how:
Here’s the lab from the article. Open the modal dialog and the popovers, then try the Escape key and clicking outside:
Finally something that makes dialogs behave like decent citizens without a ton of boilerplate. This is the closure-in-a-loop thing for accessibility: dialog.showModal() plus returnValue covers focus and answers, and Popover cleans up menus that used to require manual click-out logic.