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

Function useModal

packages/react-aria/src/overlays/useModal.tsx:180–207  ·  view source on GitHub ↗
(options?: AriaModalOptions)

Source from the content-addressed store, hash-verified

178 * accessible at once.
179 */
180export function useModal(options?: AriaModalOptions): ModalAria {
181 // Add aria-hidden to all parent providers on mount, and restore on unmount.
182 let context = useContext(Context);
183 if (!context) {
184 throw new Error('Modal is not contained within a provider');
185 }
186
187 useEffect(() => {
188 if (options?.isDisabled || !context || !context.parent) {
189 return;
190 }
191
192 // The immediate context is from the provider containing this modal, so we only
193 // want to trigger aria-hidden on its parents not on the modal provider itself.
194 context.parent.addModal();
195 return () => {
196 if (context && context.parent) {
197 context.parent.removeModal();
198 }
199 };
200 }, [context, context.parent, options?.isDisabled]);
201
202 return {
203 modalProps: {
204 'data-ismodal': !options?.isDisabled
205 }
206 };
207}

Callers 3

ModalDOMFunction · 0.90
ModalDOMFunction · 0.90
ModalDOM2Function · 0.90

Calls

no outgoing calls

Tested by 1

ModalDOMFunction · 0.72