Mantle Native Dialog Migration Guide
Dialog, AlertDialog, and Sheet no longer use Radix Dialog. Each Content renders the browser's modal <dialog>, and the panel goes inside it. The browser traps focus, makes the page inert, closes the dialog on Escape, paints it in the top layer, and returns focus to the trigger. The parts, their names, and the look stay the same, and most props do. What changes is the DOM around the panel, the reach of the modal, and the timing of the close.
TL;DR: Add modal={false} to the Root of each dialog or sheet that holds a third-party frame, such as a payment form, a 3-D Secure challenge, or a captcha. Replace a selector for [data-slot~="dialog-overlay"] (or sheet-overlay, alert-dialog-overlay) with [data-slot~="dialog-positioner"]::backdrop. In tests, getByRole("dialog") returns the <dialog>, the props of Content go to the panel inside it, and the dialog closes after its exit animation, so wait for it.
Codemod
Codemod: manual: each step depends on what a dialog holds or on a selector or a test query, which a syntax rule cannot read.
You are an agent migrating a codebase. Do this:
- Find every file that imports
Dialogfrom@ngrok/mantle/dialog,AlertDialogfrom@ngrok/mantle/alert-dialog,Sheetfrom@ngrok/mantle/sheet, orCommandfrom@ngrok/mantle/command, under any local name. - Find each of those overlays that holds a flow where a third-party script puts a frame on
<body>: Stripe Elements or Stripe.js (confirmCardSetup,confirmPayment,handleCardAction), PayPal, hCaptcha, reCAPTCHA, Turnstile, or a chat widget. Addmodal={false}to itsRoot. A modal<dialog>makes that frame inert and paints over it. Leave every other overlay modal. - Search CSS,
classNamestrings, andquerySelectorcalls fordialog-overlay,sheet-overlay, andalert-dialog-overlay. No element carries these slots now. Style the backdrop with[data-slot~="dialog-positioner"]::backdrop(orsheet-positioner,alert-dialog-positioner). - Remove
<Dialog.Overlay />and unwrap<Dialog.Portal>. Both still render (the overlay renders nothing and the portal renders its children), and both are deprecated. - Where a Radix
forceMountkept the content mounted while closed, passforceMounttoContent. RemoveforceMountfromDialog.PortalandDialog.Overlay. - Where UI must take clicks above an open overlay with the
overlay-promptclass, move that control into the overlay content. A modal<dialog>makes the rest of the page inert,overlay-promptincluded.Toastermoves its toasts into the open dialog by itself. - In tests:
getByRole("dialog")(or"alertdialog") returns the<dialog>.className,data-*,ref, anddata-appearancefromContentare on the panel inside it:dialog.querySelector('[data-slot~="dialog-content"]').- The dialog closes after its exit animation:
await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull()). - happy-dom and jsdom do not close a
<dialog>on Escape. Close it with a close button in those tests, or run the test in a browser with a real key press. - A press outside a modal dialog lands on the backdrop, which is the
<dialog>itself:await user.click(screen.getByRole("dialog")).
- After editing, run the project's formatter, linter, type checker, and tests.
Why the native
<dialog>? The browser does the focus trap, the inert page, the Escape key, the top layer, and the focus return, so mantle ships no script for them.@radix-ui/react-dialogleaves the package, and the content mounts in the frame of the tap: on a slow phone the open of a 150-element sheet takes about half the time it took with Radix.
Before → after
An overlay that holds a payment challenge
A backdrop selector
A test that reads the panel
Edge cases & gotchas
- A dialog with
modal={false}has no backdrop, paints at Tailwindz-60, and leaves the page live. Escape and a press outside close it. It no longer closes when focus leaves it. - On open, the browser focuses the first focusable element in the dialog, which can be an element with
tabindex="-1". To pick the element, useonOpenAutoFocus: callevent.preventDefault()and focus it. React'sautoFocuson an element in a dialog that mounts on open does not take focus, because React focuses the element before the dialog opens. Sandbarsits under the backdrop of a modal dialog, with the rest of the page.- Escape closes the top modal unless a listener prevents the key. An open
Select,Combobox,MultiSelect, or a popup witharia-expandedandaria-controlsin the panel takes the key first. Contenttakes noasChildand norole. It renders the<dialog>, which takes the role, and the panel inside it. Put your element insideContentinstead.AlertDialogsetsrole="alertdialog"itself.Contenthas noonFocusOutside. Focus cannot leave a modal dialog. Move the logic toonInteractOutside, or toonOpenChangefor a non-modal dialog.Titletakes noid. The dialog names itself from the id it gives the title. Passaria-labeloraria-labelledbyonContentto name it from other text.- happy-dom does not move focus into a
<dialog>onshowModal()or back onclose(), and jsdom has noshowModal(). A unit test that asserts focus on open or close runs in a real browser, such as Vitest browser mode. Escape and clicks work in both. - The exit plays in every browser: the dialog writes
data-state="closed", waits for the animations of the panel and the backdrop, and then closes.
How to verify
- Open each overlay that step 2 changed and complete its third-party flow: the frame takes clicks and keys, and the overlay stays open until your code closes it.
- Search the codebase for
dialog-overlay,sheet-overlay, andalert-dialog-overlay: no match is left. - Run the test suite. Queries for the panel read it inside the
<dialog>, and assertions after a close wait for it.