native-overlays

Installation
SKILL.md

Native Overlays

The browser has its own layer for what stands over the page. A modal <dialog> and a popover go into the top layer, above everything and unclipped by any ancestor, and the platform brings with it what libraries used to rebuild: an inert page behind a modal, Escape, focus given back, light dismiss. Use it, and know where it stops.

Native first

  • A modal is a <dialog> opened with showModal(). The browser makes the rest of the page inert, closes the dialog on Escape through its cancel event, and gives focus back to the element that had it when the dialog closes.
  • A menu, a picker, a combobox's list or a tooltip is a popover (popover, showPopover()): in the top layer, with no portal. Prefer the platform's light dismiss, popover="auto" with popovertarget on its button, before rebuilding it in script.
  • No portals and no z-index ladder: what is in the top layer stands in the order it was opened.

What a modal makes inert

  • Everything outside the open modal is inert, even what stands in the top layer: a popover, a tooltip, a toast region outside the dialog can no longer be pressed or reached.
  • So whatever a person must reach while a modal is open lives inside it: a tooltip for a control in a dialog is put inside that dialog, and a popover opened from a dialog is the dialog's descendant.

Escape and cancel

  • Chrome's close watcher honours preventDefault() on a dialog's cancel only while the page has user activation to spend: two Escapes are held, and the third closes the dialog anyway.
  • A dialog that must not close, such as one whose save is in flight, does not rely on preventDefault() alone: its owner keeps the open state, and the dialog opens itself again when it is closed against that state.
Installs
1
First Seen
8 days ago