Build a reusable Modal component and use it for a "Delete file?" confirmation.
<Modal open={open} onClose={() => setOpen(false)} title="Delete file?" initialFocusRef={cancelRef}>
…content and buttons…
</Modal>
open is false, nothing is rendered. When true, render a dimmed backdrop and a centred dialog into document.body through a portal, so parent overflow and z-index can't clip it.role="dialog", aria-modal="true", aria-labelledby → the title (rendered as a heading), and aria-describedby → the body content.initialFocusRef if given, otherwise to the dialog container itself.A full focus trap (<kbd>Tab</kbd> cycling inside the dialog) and making the background inert are the subject of Modal Dialog II. Mention them, but they aren't required here.
<dialog> element with showModal() give you for free?mousedown/click on the backdrop itself only? What bug happens when the user drags a text selection out of the dialog?Spotted a mistake or a rights concern? Report an issue