Native dialog and popover APIs can replace modal libraries in React 19
A developer argues that many React apps need not depend on libraries for modals, tooltips, and dropdowns, since browsers now handle focus trapping, Escape-key closing, outside clicks, and layering. The approach uses the HTML dialog element with showModal() inside a small React component, which places it in the top layer and returns focus to the trigger on close. CSS handles backdrop, scroll locking, and enter and exit animations, including respect for reduced-motion preferences. The popover attribute covers auto-closing menus and manual tooltips, though positioning still requires a little JavaScript until CSS anchor positioning is widely supported. The author reports rebuilding a component library this way with 30+ components, zero runtime dependencies, and about 13 KB of gzipped JavaScript.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in