Skip to content

PortalProvider

Portal provider directs portaled elements into a specified container.

The PortalProvider component sets up StrataKit’s portal context and MUI’s theme provider, so that all descendant portaled elements from StrataKit and MUI render inside the specified container instead of the default root portal container.

Use the container prop to specify the element that descendant elements are portaled into. Additionally, the unstable_getContainer prop can be used to avoid the one-commit fallback to <body> element in MUI components when the container element is not immediately available.

For example, if you use a custom or third party dialog, you can wrap its contents inside PortalProvider to ensure that all nested portaled elements appear in front of the dialog and are included in its accessibility tree.

const [container, setContainer] = React.useState(null);
<CustomDialog ref={setContainer}>
<PortalProvider container={container}>…</PortalProvider>
</CustomDialog>;