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

Function useModalOverlay

packages/react-aria/src/overlays/useModalOverlay.ts:64–100  ·  view source on GitHub ↗
(
  props: AriaModalOverlayProps,
  state: OverlayTriggerState,
  ref: RefObject<HTMLElement | null>
)

Source from the content-addressed store, hash-verified

62 * A modal is an overlay element which blocks interaction with elements outside it.
63 */
64export function useModalOverlay(
65 props: AriaModalOverlayProps,
66 state: OverlayTriggerState,
67 ref: RefObject<HTMLElement | null>
68): ModalOverlayAria {
69 let {overlayProps, underlayProps} = useOverlay(
70 {
71 ...props,
72 isOpen: state.isOpen,
73 onClose: state.close
74 },
75 ref
76 );
77
78 usePreventScroll({
79 isDisabled: !state.isOpen,
80 UNSTABLE_overrideFocus: props.UNSTABLE_overrideFocus
81 });
82
83 useOverlayFocusContain();
84
85 let {isEntering} = props;
86 useEffect(() => {
87 if (state.isOpen && ref.current) {
88 if (isEntering) {
89 // Prevent a parent modal from hiding this one while it is entering.
90 return keepVisible(ref.current);
91 }
92 return ariaHideOutside([ref.current], {shouldUseInert: true});
93 }
94 }, [state.isOpen, isEntering, ref]);
95
96 return {
97 modalProps: mergeProps(overlayProps),
98 underlayProps
99 };
100}

Callers 6

ExampleFunction · 0.90
ModalOverlayInnerFunction · 0.90
Modal.tsxFile · 0.90
Tray.tsxFile · 0.90
ToastContainerFunction · 0.90
ModalFunction · 0.90

Calls 6

useOverlayFunction · 0.90
usePreventScrollFunction · 0.90
useOverlayFocusContainFunction · 0.90
keepVisibleFunction · 0.90
ariaHideOutsideFunction · 0.90
mergePropsFunction · 0.90

Tested by 1

ExampleFunction · 0.72