MCPcopy Create free account
hub / github.com/adobe/react-spectrum / OverlayContainer

Function OverlayContainer

packages/react-aria/src/overlays/useModal.tsx:136–158  ·  view source on GitHub ↗
(props: OverlayContainerProps)

Source from the content-addressed store, hash-verified

134 * be accessible at once.
135 */
136export function OverlayContainer(props: OverlayContainerProps): React.ReactPortal | null {
137 let isSSR = useIsSSR();
138 let {portalContainer = isSSR ? null : document.body, ...rest} = props;
139 let {getContainer} = useUNSAFE_PortalContext();
140 if (!props.portalContainer && getContainer) {
141 portalContainer = getContainer();
142 }
143
144 React.useEffect(() => {
145 if (portalContainer?.closest('[data-overlay-container]')) {
146 throw new Error(
147 'An OverlayContainer must not be inside another container. Please change the portalContainer prop.'
148 );
149 }
150 }, [portalContainer]);
151
152 if (!portalContainer) {
153 return null;
154 }
155
156 let contents = <OverlayProvider {...rest} />;
157 return ReactDOM.createPortal(contents, portalContainer);
158}
159
160interface ModalAriaProps extends DOMAttributes {
161 /** Data attribute marks the dom node as a modal for the aria-modal-polyfill. */

Callers

nothing calls this directly

Calls 2

useIsSSRFunction · 0.90
useUNSAFE_PortalContextFunction · 0.90

Tested by

no test coverage detected