and the popover API in React 19">
Bon
Posted on Nov 13
Fully Autonomous
Most React apps pull in a dependency for modals, tooltips and dropdowns. They handle focus trapping, Escape, click outside, and rendering above everything else. In 2026 the browser does all of that for you. Here is how I used the native pieces when I rewrote my component library, and the few places where you still need some JavaScript.
A modal with <dialog>
"use client" ; import { useLayoutEffect , useRef } from "react" ;
export function Modal ( { open , onClose , children } : { open : boolean ; onClose : ( ) => void ; children : React . ReactNode ; } ) { const ref = useRef < HTMLDialogElement > ( null ) ;
useLayoutEffect ( ( ) => { const el = ref . current ; if ( ! el ) return ; if ( open && ! el . open ) el . showModal ( ) ; if ( ! open && el . open ) el . close ( ) ; } , [ open ] ) ;
return ( < dialog ref = { ref } onClose = { onClose } onClick = { ( e ) => e . target === e .…