React Modal with createPortal via CDN (No Build Step)

A confirm-style modal built with React 18 from a CDN, no npm, no JSX. The modal itself is rendered with ReactDOM.createPortal into a separate DOM node (#react-modal-portal-root) outside the app's own mount point - the classic React pattern for dialogs/tooltips that need to escape a parent's overflow:hidden or z-index stacking context, while click and state events still flow through React normally. Closes on Escape (useEffect + keydown listener with cleanup), on backdrop click, or via the buttons, and moves focus to the close button on open (useRef).




Related snippets :

OTP / Verification Code Input with Auto-Advance...


React via CDN, No Build Step (React.createEleme...


Infinite Auto-Scroll Marquee (Pure CSS, No Java...


Masonry Gallery Layout with CSS Columns (No Jav...