ModalProvider
ModalProvider renders one modal system into a portal.
Props
system
The instance returned by createModalSystem().
defaultOptions
Shared render and interaction defaults. Definition defaults and per-open options override these values.
portalRoot
An optional portal target. It defaults to document.body.
Lifecycle behavior
- A modal opened before mount renders when the provider becomes available.
- Escape and backdrop cancellation use distinct outcome reasons.
- Only the top modal is interactive and exposed as
aria-modal; covered and exiting layers areinert, so they cannot receive focus or clicks while an exit animation finishes. - Focus moves into the top dialog on open, and closing a layer restores the exact element that was focused before it opened (for example the trigger of the last modal) whenever that element is still in the document.
- Body scroll is locked while the stack is non-empty. The inline
overflowvalue seen on the first lock is restored once the last lock releases. - Browser Back and Forward navigation cancels the full stack with
programmatic. - Unmounting the last provider cancels pending operations with
provider-unmounted. - React Strict Mode remounts do not cancel a live operation.
Multiple providers on one document
Several providers (for example micro-frontends or embedded tools) can share one document. The library coordinates their side effects per document:
- Body scroll stays locked until every provider with open modals closes them,
regardless of the closing or unmounting order. While locked, the body's
overscroll-behavioris set tonone, and the owning provider cancels touch drags that start outside its stack (mobile Safari keeps scrolling aoverflow: hiddenbody otherwise). Dialog bodies setoverscroll-behavior: containso their internal scrolling never chains to the page. - The provider that opened the most recent modal owns Escape and Tab. Other
providers keep their stacks untouched, and a top modal with
closeOnPressEsc: falseblocks Escape for every provider. - Focus that escapes the stack programmatically (application code focusing a background element while a modal is open) is pulled back into the top dialog, restoring the element that was focused last inside it.
- The most recent provider also renders on top: each claim moves the provider's portal container above every other provider's, so Escape, Tab and pointer order match the visual order.
- When the owning provider unmounts or empties its stack, keyboard ownership returns to the remaining provider.
- Providers portaled into another document (for example inside an
iframe) lock and listen within that document only.
