@activecollab/components 2.0.547 → 2.0.549

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -186,9 +186,12 @@ export const Menu = _ref4 => {
186
186
  const _useState = useState(defaultOpen),
187
187
  open = _useState[0],
188
188
  setOpen = _useState[1];
189
- const _useState2 = useState(!defaultOpen),
190
- exited = _useState2[0],
191
- setExited = _useState2[1];
189
+ const _useState2 = useState(defaultOpen),
190
+ syncedOpen = _useState2[0],
191
+ setSyncedOpen = _useState2[1];
192
+ const _useState3 = useState(!defaultOpen),
193
+ exited = _useState3[0],
194
+ setExited = _useState3[1];
192
195
  // The trigger node lives in a ref. In state it would render every menu of a list again right after it mounts.
193
196
  const elementRef = useRef(null);
194
197
  const isOpenAtLeastOnce = useRef(false);
@@ -199,6 +202,10 @@ export const Menu = _ref4 => {
199
202
  const popperRef = useRef(null);
200
203
  const windowRef = useRef(null);
201
204
  const tabOut = useRef(0);
205
+ if (defaultOpen !== syncedOpen) {
206
+ setSyncedOpen(defaultOpen);
207
+ setOpen(defaultOpen);
208
+ }
202
209
 
203
210
  // Read on the render that opens the menu, before the focus lock moves the focus inside it.
204
211
  if (open && !wasOpen.current && typeof document !== "undefined") {
@@ -206,13 +213,6 @@ export const Menu = _ref4 => {
206
213
  focusWasVisible.current = isFocusVisible(document.activeElement);
207
214
  }
208
215
  wasOpen.current = open;
209
-
210
- // Layout effects, so a menu that closes in the same update in which an item opens a dialog gives the focus back to
211
- // its trigger before the dialog calls showModal. The dialog then returns the focus to the trigger, not to an item
212
- // that is gone.
213
- useLayoutEffect(() => {
214
- setOpen(defaultOpen);
215
- }, [defaultOpen]);
216
216
  useEffect(() => {
217
217
  if (open) {
218
218
  setExited(false);
@@ -253,9 +253,9 @@ export const Menu = _ref4 => {
253
253
  const handleRef = useForkRef(target ? target.ref : undefined, elementRef);
254
254
 
255
255
  // The popper needs the node as state, so it is copied only while the menu shows, before the browser paints.
256
- const _useState3 = useState(null),
257
- childNode = _useState3[0],
258
- setChildNode = _useState3[1];
256
+ const _useState4 = useState(null),
257
+ childNode = _useState4[0],
258
+ setChildNode = _useState4[1];
259
259
  useLayoutEffect(() => {
260
260
  const node = open || !exited ? elementRef.current : null;
261
261
  if (node !== childNode) {
@@ -292,18 +292,18 @@ export const Menu = _ref4 => {
292
292
  const childProps = {
293
293
  forceClose: handleClose
294
294
  };
295
- const _useState4 = useState(false),
296
- focusedInside = _useState4[0],
297
- setFocusedInside = _useState4[1];
295
+ const _useState5 = useState(false),
296
+ focusedInside = _useState5[0],
297
+ setFocusedInside = _useState5[1];
298
298
  const markFocusedInside = useCallback(() => setFocusedInside(true), []);
299
299
  useEffect(() => {
300
300
  if (!open) {
301
301
  setFocusedInside(false);
302
302
  }
303
303
  }, [open]);
304
- const _useState5 = useState("off"),
305
- prerenderStep = _useState5[0],
306
- setPrerenderStep = _useState5[1];
304
+ const _useState6 = useState("off"),
305
+ prerenderStep = _useState6[0],
306
+ setPrerenderStep = _useState6[1];
307
307
 
308
308
  // The caller can turn it on later, for example once the form that holds the menu has finished opening.
309
309
  useEffect(() => {
@@ -358,6 +358,10 @@ export const Menu = _ref4 => {
358
358
  document.removeEventListener("pointerdown", closeOnPressOutside);
359
359
  };
360
360
  }, [open]);
361
+
362
+ // The open prop is synced while rendering and the focus returns in a layout effect, so a menu that closes in the same
363
+ // update in which an item opens a dialog gives the focus back to its trigger before the dialog calls showModal, in a
364
+ // later commit, wherever the dialog sits in the tree. The dialog then returns the focus to the trigger.
361
365
  useLayoutEffect(() => {
362
366
  if (open) {
363
367
  isOpenAtLeastOnce.current = true;
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.js","names":["React","useRef","useState","useCallback","useEffect","useLayoutEffect","useMemo","classnames","MenuContextProvider","StyledMenu","Portal","useForkRef","Overlay","Popper","Grow","Window","isFocusVisible","element","Boolean","matches","_unused","TRIGGER","triggerOf","node","_node$querySelector","querySelector","visibleBoxOf","rects","getBoundingClientRect","Array","from","children","map","filter","rect","width","height","left","Math","min","right","max","top","bottom","offsetToVisibleBox","name","options","offset","_ref","placement","wrapper","box","_placement$split","split","side","align","vertical","start","end","skidding","distance","TABBABLE","returnFocusOptions","visible","focusVisible","focusTabNeighbor","trigger","step","menu","nodes","document","querySelectorAll","tabIndex","disabled","closest","contains","indexOf","index","length","focus","activeElement","isOnLayerAbove","target","own","Element","modalDialog","layer","layerZ","Number","style","zIndex","ownZ","compareDocumentPosition","Node","DOCUMENT_POSITION_FOLLOWING","PRERENDER_DELAY","PRERENDER_GAP","prerenderQueue","prerenderTimer","runPrerenderQueue","_prerenderQueue$shift","shift","setTimeout","queuePrerender","render","push","splice","FocusInside","_ref2","onFocused","ref","_ref$current","_ref3","current","parentElement","first","find","preventScroll","createElement","hidden","Menu","_ref4","_ref4$disableFocusLoc","disableFocusLock","onMenuClick","_ref4$handleScroll","handleScroll","_ref4$mode","mode","_ref4$open","open","defaultOpen","onOpen","onClose","onBeforeClose","_ref4$position","position","className","menuClassName","popperClassName","backgroundElementClass","_ref4$windowAbsolutel","windowAbsolutelyPositioned","onPopperOpen","_ref4$closeOnTab","closeOnTab","_ref4$prerender","prerender","_ref4$scopedFocus","scopedFocus","_useState","setOpen","_useState2","exited","setExited","elementRef","isOpenAtLeastOnce","wasOpen","focusBeforeOpen","focusWasVisible","returnFocusTo","popperRef","windowRef","tabOut","expandedTrigger","checkedTrigger","triggerOwnsExpanded","hasAttribute","setAttribute","removeAttribute","handleRef","undefined","_useState3","childNode","setChildNode","popperModifiers","HTMLElement","handleOpen","event","_target$props","preventDefault","stopPropagation","props","onClick","handleClose","handleTabOut","key","defaultPrevented","shiftKey","childProps","forceClose","_useState4","focusedInside","setFocusedInside","markFocusedInside","_useState5","prerenderStep","setPrerenderStep","handleCloseRef","handleTargetClose","targetProps","pressInside","markPressInside","nativeEvent","closeOnPressOutside","_elementRef$current","timer","addEventListener","clearTimeout","removeEventListener","previous","tabbedTo","returnTo","isConnected","keepFocusOut","_popperRef$current","_returnFocusTo$curren","Fragment","cloneElement","value","onKeyDown","disableReturnFocus","disableScrollLock","isolateScroll","disableCloseOnEsc","onPointerDownCapture","pointerEvents","disableBackgroundColor","anchorEl","afterWrite","modifiers","transition","_ref5","_elementRef$current2","transitionProps","in","onEnter","onExited","$mode","onMouseDown","offsetWidth","displayName"],"sources":["../../../../src/components/Menu/Menu.tsx"],"sourcesContent":["import React, {\n useRef,\n FC,\n ReactNode,\n MouseEvent,\n KeyboardEvent,\n useState,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n ReactElement,\n Ref,\n} from \"react\";\n\nimport { Placement } from \"@popperjs/core\";\nimport classnames from \"classnames\";\n\nimport { MenuContextProvider } from \"./context\";\nimport { StyledMenu } from \"./Styles\";\nimport { Portal } from \"../../helpers\";\nimport useForkRef from \"../../utils/useForkRef\";\nimport { Overlay } from \"../Overlay\";\nimport { Popper } from \"../Popper\";\nimport { Grow } from \"../Transitions\";\nimport { Window } from \"../Window\";\n\ninterface ElementWithRef<T> extends ReactElement {\n ref?: Ref<T>;\n}\n\n// source: https://twitter.com/mattpocockuk/status/1671908303918473217/photo/1\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type MenuMode = \"normal\" | \"wider\" | \"tiny\" | \"widest\";\n\nexport interface IMenu {\n /** Menu content */\n children:\n | ReactNode\n | ((childProps: { forceClose: () => void }) => JSX.Element);\n /** On menu element click */\n onMenuClick?: (event: MouseEvent<HTMLElement>) => void;\n /** Handle scroll bar */\n handleScroll?: boolean;\n /** Disable Focus Lock */\n disableFocusLock?: boolean;\n /** Menu width mode */\n mode?: MenuMode;\n /** A width in pixels, or \"target\" for the width of the target. It wins over the mode. */\n width?: number | \"target\";\n /** Should menu be open when it's mounted */\n open?: boolean;\n /** Callback triggered when modal has been opened */\n onOpen?: () => void;\n /** Callback triggered when modal has been closed */\n onClose?: () => void;\n /** Before close callback */\n onBeforeClose?: () => boolean;\n /** Position Menu */\n position?: Placement;\n /** Target element */\n target?: ElementWithRef<Element>;\n className?: string;\n /** Menu classes */\n menuClassName?: string;\n /** Popper class name*/\n popperClassName?: string;\n /** Background style for clickable element after the menu is open (opacity, color, etc...) */\n backgroundElementClass?: string;\n /** Should Window be positioned absolutely */\n windowAbsolutelyPositioned?: boolean;\n /** Popper on open */\n onPopperOpen?: (...args) => void;\n /** Tab and Shift+Tab close the menu and move the focus on from the target, as they would on the target itself */\n closeOnTab?: boolean;\n /** Render the content once, hidden, soon after this turns on, so the first open is as fast as the next ones */\n prerender?: boolean;\n /** Move the focus into the menu itself, so the focus lock never searches the whole page for a place to put it */\n scopedFocus?: boolean;\n}\n\nconst isFocusVisible = (element: Element | null) => {\n try {\n return Boolean(element?.matches(\":focus-visible\"));\n } catch {\n return false;\n }\n};\n\nconst TRIGGER = 'button, [role=\"button\"], a[href]';\n\n// A target can wrap its button, as a div around a Tooltip or a CounterButton does.\nconst triggerOf = (node: HTMLElement) =>\n node.matches(TRIGGER)\n ? node\n : node.querySelector<HTMLElement>(TRIGGER) ?? node;\n\nconst visibleBoxOf = (node: HTMLElement) => {\n // A child hidden by a breakpoint has an empty box at 0,0, so it must not count.\n const rects = [\n node.getBoundingClientRect(),\n ...Array.from(node.children)\n .map((element) => element.getBoundingClientRect())\n .filter((rect) => rect.width > 0 || rect.height > 0),\n ];\n\n return {\n left: Math.min(...rects.map((rect) => rect.left)),\n right: Math.max(...rects.map((rect) => rect.right)),\n top: Math.min(...rects.map((rect) => rect.top)),\n bottom: Math.max(...rects.map((rect) => rect.bottom)),\n };\n};\n\n// A control group pulls a wrapped button out of its wrapper by negative margins, so the menu lines up with the button.\nconst offsetToVisibleBox = (node: HTMLElement) => ({\n name: \"offset\",\n options: {\n offset: ({ placement }: { placement: Placement }): [number, number] => {\n if (triggerOf(node) === node) {\n return [0, 0];\n }\n\n const wrapper = node.getBoundingClientRect();\n const box = visibleBoxOf(node);\n const [side, align] = placement.split(\"-\");\n const vertical = side === \"top\" || side === \"bottom\";\n const start = vertical ? \"left\" : \"top\";\n const end = vertical ? \"right\" : \"bottom\";\n const skidding =\n align === \"start\"\n ? box[start] - wrapper[start]\n : align === \"end\"\n ? box[end] - wrapper[end]\n : (box[start] + box[end] - wrapper[start] - wrapper[end]) / 2;\n const distance = {\n bottom: box.bottom - wrapper.bottom,\n top: wrapper.top - box.top,\n right: box.right - wrapper.right,\n left: wrapper.left - box.left,\n }[side];\n\n return [skidding, distance ?? 0];\n },\n },\n});\n\nconst TABBABLE =\n 'a[href], button, input, select, textarea, iframe, [tabindex], [contenteditable=\"true\"]';\n\n// A menu opened with the pointer hands the focus back without a focus ring, so its trigger does not stay lit.\nconst returnFocusOptions = (visible: boolean) =>\n ({ focusVisible: visible } as FocusOptions);\n\n// Moves the focus where a Tab or Shift+Tab on the trigger would go. The closing menu itself does not count.\nconst focusTabNeighbor = (\n trigger: HTMLElement,\n step: 1 | -1,\n menu: HTMLElement | null\n) => {\n const nodes = Array.from(\n document.querySelectorAll<HTMLElement>(TABBABLE)\n ).filter(\n (node) =>\n node === trigger ||\n (node.tabIndex >= 0 &&\n !(node as HTMLButtonElement).disabled &&\n !node.closest(\"[inert]\") &&\n !menu?.contains(node))\n );\n\n const from = nodes.indexOf(trigger);\n\n for (\n let index = from + step;\n from !== -1 && index >= 0 && index < nodes.length;\n index += step\n ) {\n nodes[index].focus(returnFocusOptions(true));\n\n if (document.activeElement === nodes[index]) {\n return nodes[index];\n }\n }\n\n return null;\n};\n\n// A press on a layer above the menu, such as a dialog it opened, never reached the old overlay either.\n// An open native dialog that does not hold the menu sits above it in the top layer.\nconst isOnLayerAbove = (\n target: EventTarget | null,\n own: HTMLElement | null\n) => {\n if (!(target instanceof Element) || !own) {\n return false;\n }\n\n const modalDialog = target.closest(\"dialog[open]\");\n\n if (modalDialog && !modalDialog.contains(own)) {\n return true;\n }\n\n const layer = target.closest<HTMLElement>(\".c-window\");\n\n if (!layer || layer === own) {\n return false;\n }\n\n const layerZ = Number(layer.style.zIndex) || 0;\n const ownZ = Number(own.style.zIndex) || 0;\n\n return (\n layerZ > ownZ ||\n (layerZ === ownZ &&\n Boolean(\n own.compareDocumentPosition(layer) & Node.DOCUMENT_POSITION_FOLLOWING\n ))\n );\n};\n\nconst PRERENDER_DELAY = 50;\nconst PRERENDER_GAP = 50;\nconst prerenderQueue: (() => void)[] = [];\nlet prerenderTimer: ReturnType<typeof setTimeout> | null = null;\n\nconst runPrerenderQueue = () => {\n prerenderQueue.shift()?.();\n prerenderTimer = prerenderQueue.length\n ? setTimeout(runPrerenderQueue, PRERENDER_GAP)\n : null;\n};\n\n// One menu at a time, a moment after the caller turns it on, so no frame carries more than one render.\nconst queuePrerender = (render: () => void) => {\n prerenderQueue.push(render);\n\n if (!prerenderTimer) {\n prerenderTimer = setTimeout(runPrerenderQueue, PRERENDER_DELAY);\n }\n\n return () => {\n const index = prerenderQueue.indexOf(render);\n\n if (index !== -1) {\n prerenderQueue.splice(index, 1);\n }\n };\n};\n\n// Its layout effect runs before the popper ref is set, so it finds the menu through its own node.\nconst FocusInside: FC<{ onFocused: () => void }> = ({ onFocused }) => {\n const ref = useRef<HTMLSpanElement>(null);\n\n useLayoutEffect(() => {\n const menu = ref.current?.parentElement;\n\n if (!menu) {\n return;\n }\n\n if (menu.contains(document.activeElement)) {\n onFocused();\n return;\n }\n\n const first = Array.from(menu.querySelectorAll<HTMLElement>(TABBABLE)).find(\n (node) => node.tabIndex >= 0 && !(node as HTMLButtonElement).disabled\n );\n\n (first ?? menu.closest<HTMLElement>(\"[tabindex]\"))?.focus({\n preventScroll: true,\n });\n onFocused();\n }, [onFocused]);\n\n return <span ref={ref} hidden />;\n};\n\nexport const Menu: FC<IMenu> = ({\n children,\n disableFocusLock = false,\n onMenuClick,\n handleScroll = true,\n mode = \"normal\",\n width,\n open: defaultOpen = false,\n onOpen,\n onClose,\n onBeforeClose,\n position = \"bottom-start\",\n target,\n className,\n menuClassName,\n popperClassName,\n backgroundElementClass,\n windowAbsolutelyPositioned = false,\n onPopperOpen,\n closeOnTab = false,\n prerender = false,\n scopedFocus = false,\n}) => {\n const [open, setOpen] = useState(defaultOpen);\n const [exited, setExited] = useState(!defaultOpen);\n // The trigger node lives in a ref. In state it would render every menu of a list again right after it mounts.\n const elementRef = useRef<HTMLElement | null>(null);\n const isOpenAtLeastOnce = useRef(false);\n const wasOpen = useRef(open);\n const focusBeforeOpen = useRef<Element | null>(null);\n const focusWasVisible = useRef(false);\n const returnFocusTo = useRef<HTMLElement | null>(null);\n const popperRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n const tabOut = useRef<1 | -1 | 0>(0);\n\n // Read on the render that opens the menu, before the focus lock moves the focus inside it.\n if (open && !wasOpen.current && typeof document !== \"undefined\") {\n focusBeforeOpen.current = document.activeElement;\n focusWasVisible.current = isFocusVisible(document.activeElement);\n }\n wasOpen.current = open;\n\n // Layout effects, so a menu that closes in the same update in which an item opens a dialog gives the focus back to\n // its trigger before the dialog calls showModal. The dialog then returns the focus to the trigger, not to an item\n // that is gone.\n useLayoutEffect(() => {\n setOpen(defaultOpen);\n }, [defaultOpen]);\n\n useEffect(() => {\n if (open) {\n setExited(false);\n }\n }, [open]);\n\n // Set on the node itself, so the trigger gets it also through a wrapper such as Tooltip. It runs after every\n // render, because the trigger node lives in a ref and a new node brings no render of its own.\n const expandedTrigger = useRef<HTMLElement | null>(null);\n const checkedTrigger = useRef<HTMLElement | null>(null);\n const triggerOwnsExpanded = useRef(false);\n\n useEffect(() => {\n const node = elementRef.current;\n\n if (!node) {\n return;\n }\n\n const trigger = triggerOf(node);\n\n // A trigger that renders its own aria-expanded keeps it, so the menu never clears its \"false\".\n if (checkedTrigger.current !== trigger) {\n checkedTrigger.current = trigger;\n triggerOwnsExpanded.current = trigger.hasAttribute(\"aria-expanded\");\n }\n\n if (!trigger.hasAttribute(\"aria-haspopup\")) {\n trigger.setAttribute(\"aria-haspopup\", \"true\");\n }\n\n if (triggerOwnsExpanded.current) {\n return;\n }\n\n if (open) {\n trigger.setAttribute(\"aria-expanded\", \"true\");\n expandedTrigger.current = trigger;\n } else if (expandedTrigger.current) {\n expandedTrigger.current.removeAttribute(\"aria-expanded\");\n expandedTrigger.current = null;\n }\n });\n\n const handleRef = useForkRef(target ? target.ref : undefined, elementRef);\n\n // The popper needs the node as state, so it is copied only while the menu shows, before the browser paints.\n const [childNode, setChildNode] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n const node = open || !exited ? elementRef.current : null;\n\n if (node !== childNode) {\n setChildNode(node);\n }\n }, [open, exited, childNode]);\n\n const popperModifiers = useMemo(\n () =>\n childNode instanceof HTMLElement\n ? [offsetToVisibleBox(childNode)]\n : undefined,\n [childNode]\n );\n\n const handleOpen = useCallback(\n (\n event: Pick<MouseEvent<Element>, \"preventDefault\" | \"stopPropagation\">\n ) => {\n event?.preventDefault();\n event?.stopPropagation();\n setOpen(true);\n typeof onOpen === \"function\" && onOpen();\n typeof target?.props?.onClick === \"function\" &&\n target.props.onClick(event);\n },\n [onOpen, target?.props]\n );\n\n const handleClose = useCallback(() => {\n if (typeof onBeforeClose === \"function\" && !onBeforeClose()) {\n return false;\n }\n setOpen(false);\n typeof onClose === \"function\" && onClose();\n\n return true;\n }, [onClose, onBeforeClose]);\n\n const handleTabOut = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== \"Tab\" || event.defaultPrevented) {\n return;\n }\n\n event.preventDefault();\n tabOut.current = event.shiftKey ? -1 : 1;\n\n if (!handleClose()) {\n tabOut.current = 0;\n }\n },\n [handleClose]\n );\n\n const childProps = {\n forceClose: handleClose,\n };\n\n const [focusedInside, setFocusedInside] = useState(false);\n const markFocusedInside = useCallback(() => setFocusedInside(true), []);\n\n useEffect(() => {\n if (!open) {\n setFocusedInside(false);\n }\n }, [open]);\n\n const [prerenderStep, setPrerenderStep] = useState<\n \"off\" | \"waiting\" | \"rendering\" | \"done\"\n >(\"off\");\n\n // The caller can turn it on later, for example once the form that holds the menu has finished opening.\n useEffect(() => {\n if (prerender && prerenderStep === \"off\") {\n setPrerenderStep(\"waiting\");\n }\n }, [prerender, prerenderStep]);\n\n useEffect(() => {\n if (prerenderStep === \"off\" || prerenderStep === \"done\") {\n return undefined;\n }\n\n if (prerenderStep === \"rendering\") {\n setPrerenderStep(\"done\");\n\n return undefined;\n }\n\n return queuePrerender(() => setPrerenderStep(\"rendering\"));\n }, [prerenderStep]);\n\n const handleCloseRef = useRef(handleClose);\n handleCloseRef.current = handleClose;\n\n const handleTargetClose = useCallback(\n (\n event: Pick<MouseEvent<Element>, \"preventDefault\" | \"stopPropagation\">\n ) => {\n event?.preventDefault();\n event?.stopPropagation();\n handleClose();\n },\n [handleClose]\n );\n\n const targetProps = {\n open,\n ref: handleRef,\n onClick: open ? handleTargetClose : handleOpen,\n };\n\n // React carries the press through portals, so a nested menu or dialog counts as inside.\n const pressInside = useRef<Event | null>(null);\n const markPressInside = useCallback((event: React.PointerEvent) => {\n pressInside.current = event.nativeEvent;\n }, []);\n\n useEffect(() => {\n if (!open) {\n return undefined;\n }\n\n const closeOnPressOutside = (event: Event) => {\n if (\n pressInside.current === event ||\n elementRef.current?.contains(event.target as Node) ||\n isOnLayerAbove(event.target, windowRef.current)\n ) {\n return;\n }\n\n handleCloseRef.current();\n };\n\n // Armed after the press that opened the menu has passed the document.\n const timer = setTimeout(() =>\n document.addEventListener(\"pointerdown\", closeOnPressOutside)\n );\n\n return () => {\n clearTimeout(timer);\n document.removeEventListener(\"pointerdown\", closeOnPressOutside);\n };\n }, [open]);\n\n useLayoutEffect(() => {\n if (open) {\n isOpenAtLeastOnce.current = true;\n } else if (!open && isOpenAtLeastOnce.current) {\n const previous = focusBeforeOpen.current;\n const step = tabOut.current;\n const tabbedTo =\n step && elementRef.current\n ? focusTabNeighbor(\n triggerOf(elementRef.current),\n step,\n windowRef.current\n )\n : null;\n\n tabOut.current = 0;\n\n if (tabbedTo) {\n returnFocusTo.current = tabbedTo;\n } else {\n const returnTo =\n previous instanceof HTMLElement && previous.isConnected\n ? previous\n : elementRef.current;\n\n returnFocusTo.current = returnTo;\n returnTo?.focus(returnFocusOptions(focusWasVisible.current));\n }\n isOpenAtLeastOnce.current = false;\n }\n }, [open]);\n\n // A fading menu is already closed. Its content can still reach for the focus, and would take it away\n // with it when it unmounts, so the focus goes straight back to where the menu returned it.\n useEffect(() => {\n if (open || exited) {\n return undefined;\n }\n\n const keepFocusOut = (event: FocusEvent) => {\n if (popperRef.current?.contains(event.target as Node)) {\n returnFocusTo.current?.focus(\n returnFocusOptions(focusWasVisible.current)\n );\n }\n };\n\n document.addEventListener(\"focusin\", keepFocusOut, true);\n\n return () => document.removeEventListener(\"focusin\", keepFocusOut, true);\n }, [open, exited]);\n\n return (\n <>\n {target && React.cloneElement(target, targetProps)}\n {prerenderStep === \"rendering\" && !open && exited ? (\n <Portal>\n <div hidden aria-hidden>\n <MenuContextProvider value={{ open: false, setOpen }}>\n {typeof children === \"function\" ? children(childProps) : children}\n </MenuContextProvider>\n </div>\n </Portal>\n ) : null}\n {open || !exited ? (\n <Window\n ref={windowRef}\n onClose={handleClose}\n onKeyDown={closeOnTab && open ? handleTabOut : undefined}\n // The lock returns the focus with the props of the render before it turns off, too late to skip a Tab.\n // The menu returns the focus itself, so a menu that closes on Tab leaves the lock out of it.\n disableReturnFocus={closeOnTab}\n disableScrollLock={!handleScroll || !open}\n isolateScroll\n // The menu returns the focus itself at once, so a late returnFocus cannot undo a caller's move.\n // With the focus already inside, the lock turns on without searching the page for a place to put it.\n disableFocusLock={\n disableFocusLock || !open || (scopedFocus && !focusedInside)\n }\n // A fading menu is already closed, so an escape pressed meanwhile belongs to the page behind it.\n disableCloseOnEsc={!open}\n onPointerDownCapture={markPressInside}\n // Only the overlay and the menu take the pointer, so the first click outside only closes the menu.\n style={{\n position: windowAbsolutelyPositioned ? \"absolute\" : \"fixed\",\n pointerEvents: \"none\",\n }}\n >\n {open ? (\n <Overlay\n className={backgroundElementClass}\n disableBackgroundColor\n // Closing on the click, not the press, keeps the whole click on the overlay.\n onClick={handleClose}\n tabIndex={-1}\n style={{ pointerEvents: \"auto\" }}\n />\n ) : null}\n <Popper\n ref={popperRef}\n anchorEl={childNode}\n open={childNode ? open : false}\n placement={position}\n className={popperClassName}\n tabIndex={-1}\n afterWrite={onPopperOpen}\n modifiers={popperModifiers}\n transition\n >\n {({ placement, transitionProps }) => (\n <Grow\n placement={placement}\n in={transitionProps?.in}\n onEnter={transitionProps?.onEnter}\n onExited={() => {\n setExited(true);\n transitionProps?.onExited?.();\n }}\n >\n <StyledMenu\n className={classnames(\n \"c-simple-menu__paper\",\n `c-simple-menu__${mode}`,\n menuClassName,\n className\n )}\n $mode={mode}\n onMouseDown={onMenuClick}\n style={{\n pointerEvents: open ? \"auto\" : \"none\",\n width:\n width === \"target\"\n ? elementRef.current?.offsetWidth\n : width,\n }}\n >\n <MenuContextProvider value={{ open, setOpen }}>\n {typeof children === \"function\"\n ? children(childProps)\n : children}\n </MenuContextProvider>\n {scopedFocus && open ? (\n <FocusInside onFocused={markFocusedInside} />\n ) : null}\n </StyledMenu>\n </Grow>\n )}\n </Popper>\n </Window>\n ) : null}\n </>\n );\n};\n\nMenu.displayName = \"Menu\";\n"],"mappings":"AAAA,OAAOA,KAAK,IACVC,MAAM,EAKNC,QAAQ,EACRC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,OAAO,QAGF,OAAO;AAGd,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,mBAAmB,QAAQ,WAAW;AAC/C,SAASC,UAAU,QAAQ,UAAU;AACrC,SAASC,MAAM,QAAQ,eAAe;AACtC,OAAOC,UAAU,MAAM,wBAAwB;AAC/C,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,IAAI,QAAQ,gBAAgB;AACrC,SAASC,MAAM,QAAQ,WAAW;;AAMlC;AACA;;AAiDA,MAAMC,cAAc,GAAIC,OAAuB,IAAK;EAClD,IAAI;IACF,OAAOC,OAAO,CAACD,OAA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AC/B7M;MACR;IAAE,gBAEFnC,KAAA,CAAAsH,aAAA,CAAC9G,mBAAmB;MAACmN,KAAK,EAAE;QAAEzF,IAAI;QAAEqB;MAAQ;IAAE,GAC3C,OAAOxH,QAAQ,KAAK,UAAU,GAC3BA,QAAQ,CAAC8J,UAAU,CAAC,GACpB9J,QACe,CAAC,EACrBsH,WAAW,IAAInB,IAAI,gBAClBlI,KAAA,CAAAsH,aAAA,CAACX,WAAW;MAACE,SAAS,EAAEqF;IAAkB,CAAE,CAAC,GAC3C,IACM,CACR,CAAC;EAAA,CAEH,CACF,CAAC,GACP,IACJ,CAAC;AAEP,CAAC;AAED1E,IAAI,CAACyH,WAAW,GAAG,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"Menu.js","names":["React","useRef","useState","useCallback","useEffect","useLayoutEffect","useMemo","classnames","MenuContextProvider","StyledMenu","Portal","useForkRef","Overlay","Popper","Grow","Window","isFocusVisible","element","Boolean","matches","_unused","TRIGGER","triggerOf","node","_node$querySelector","querySelector","visibleBoxOf","rects","getBoundingClientRect","Array","from","children","map","filter","rect","width","height","left","Math","min","right","max","top","bottom","offsetToVisibleBox","name","options","offset","_ref","placement","wrapper","box","_placement$split","split","side","align","vertical","start","end","skidding","distance","TABBABLE","returnFocusOptions","visible","focusVisible","focusTabNeighbor","trigger","step","menu","nodes","document","querySelectorAll","tabIndex","disabled","closest","contains","indexOf","index","length","focus","activeElement","isOnLayerAbove","target","own","Element","modalDialog","layer","layerZ","Number","style","zIndex","ownZ","compareDocumentPosition","Node","DOCUMENT_POSITION_FOLLOWING","PRERENDER_DELAY","PRERENDER_GAP","prerenderQueue","prerenderTimer","runPrerenderQueue","_prerenderQueue$shift","shift","setTimeout","queuePrerender","render","push","splice","FocusInside","_ref2","onFocused","ref","_ref$current","_ref3","current","parentElement","first","find","preventScroll","createElement","hidden","Menu","_ref4","_ref4$disableFocusLoc","disableFocusLock","onMenuClick","_ref4$handleScroll","handleScroll","_ref4$mode","mode","_ref4$open","open","defaultOpen","onOpen","onClose","onBeforeClose","_ref4$position","position","className","menuClassName","popperClassName","backgroundElementClass","_ref4$windowAbsolutel","windowAbsolutelyPositioned","onPopperOpen","_ref4$closeOnTab","closeOnTab","_ref4$prerender","prerender","_ref4$scopedFocus","scopedFocus","_useState","setOpen","_useState2","syncedOpen","setSyncedOpen","_useState3","exited","setExited","elementRef","isOpenAtLeastOnce","wasOpen","focusBeforeOpen","focusWasVisible","returnFocusTo","popperRef","windowRef","tabOut","expandedTrigger","checkedTrigger","triggerOwnsExpanded","hasAttribute","setAttribute","removeAttribute","handleRef","undefined","_useState4","childNode","setChildNode","popperModifiers","HTMLElement","handleOpen","event","_target$props","preventDefault","stopPropagation","props","onClick","handleClose","handleTabOut","key","defaultPrevented","shiftKey","childProps","forceClose","_useState5","focusedInside","setFocusedInside","markFocusedInside","_useState6","prerenderStep","setPrerenderStep","handleCloseRef","handleTargetClose","targetProps","pressInside","markPressInside","nativeEvent","closeOnPressOutside","_elementRef$current","timer","addEventListener","clearTimeout","removeEventListener","previous","tabbedTo","returnTo","isConnected","keepFocusOut","_popperRef$current","_returnFocusTo$curren","Fragment","cloneElement","value","onKeyDown","disableReturnFocus","disableScrollLock","isolateScroll","disableCloseOnEsc","onPointerDownCapture","pointerEvents","disableBackgroundColor","anchorEl","afterWrite","modifiers","transition","_ref5","_elementRef$current2","transitionProps","in","onEnter","onExited","$mode","onMouseDown","offsetWidth","displayName"],"sources":["../../../../src/components/Menu/Menu.tsx"],"sourcesContent":["import React, {\n useRef,\n FC,\n ReactNode,\n MouseEvent,\n KeyboardEvent,\n useState,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n ReactElement,\n Ref,\n} from \"react\";\n\nimport { Placement } from \"@popperjs/core\";\nimport classnames from \"classnames\";\n\nimport { MenuContextProvider } from \"./context\";\nimport { StyledMenu } from \"./Styles\";\nimport { Portal } from \"../../helpers\";\nimport useForkRef from \"../../utils/useForkRef\";\nimport { Overlay } from \"../Overlay\";\nimport { Popper } from \"../Popper\";\nimport { Grow } from \"../Transitions\";\nimport { Window } from \"../Window\";\n\ninterface ElementWithRef<T> extends ReactElement {\n ref?: Ref<T>;\n}\n\n// source: https://twitter.com/mattpocockuk/status/1671908303918473217/photo/1\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type MenuMode = \"normal\" | \"wider\" | \"tiny\" | \"widest\";\n\nexport interface IMenu {\n /** Menu content */\n children:\n | ReactNode\n | ((childProps: { forceClose: () => void }) => JSX.Element);\n /** On menu element click */\n onMenuClick?: (event: MouseEvent<HTMLElement>) => void;\n /** Handle scroll bar */\n handleScroll?: boolean;\n /** Disable Focus Lock */\n disableFocusLock?: boolean;\n /** Menu width mode */\n mode?: MenuMode;\n /** A width in pixels, or \"target\" for the width of the target. It wins over the mode. */\n width?: number | \"target\";\n /** Should menu be open when it's mounted */\n open?: boolean;\n /** Callback triggered when modal has been opened */\n onOpen?: () => void;\n /** Callback triggered when modal has been closed */\n onClose?: () => void;\n /** Before close callback */\n onBeforeClose?: () => boolean;\n /** Position Menu */\n position?: Placement;\n /** Target element */\n target?: ElementWithRef<Element>;\n className?: string;\n /** Menu classes */\n menuClassName?: string;\n /** Popper class name*/\n popperClassName?: string;\n /** Background style for clickable element after the menu is open (opacity, color, etc...) */\n backgroundElementClass?: string;\n /** Should Window be positioned absolutely */\n windowAbsolutelyPositioned?: boolean;\n /** Popper on open */\n onPopperOpen?: (...args) => void;\n /** Tab and Shift+Tab close the menu and move the focus on from the target, as they would on the target itself */\n closeOnTab?: boolean;\n /** Render the content once, hidden, soon after this turns on, so the first open is as fast as the next ones */\n prerender?: boolean;\n /** Move the focus into the menu itself, so the focus lock never searches the whole page for a place to put it */\n scopedFocus?: boolean;\n}\n\nconst isFocusVisible = (element: Element | null) => {\n try {\n return Boolean(element?.matches(\":focus-visible\"));\n } catch {\n return false;\n }\n};\n\nconst TRIGGER = 'button, [role=\"button\"], a[href]';\n\n// A target can wrap its button, as a div around a Tooltip or a CounterButton does.\nconst triggerOf = (node: HTMLElement) =>\n node.matches(TRIGGER)\n ? node\n : node.querySelector<HTMLElement>(TRIGGER) ?? node;\n\nconst visibleBoxOf = (node: HTMLElement) => {\n // A child hidden by a breakpoint has an empty box at 0,0, so it must not count.\n const rects = [\n node.getBoundingClientRect(),\n ...Array.from(node.children)\n .map((element) => element.getBoundingClientRect())\n .filter((rect) => rect.width > 0 || rect.height > 0),\n ];\n\n return {\n left: Math.min(...rects.map((rect) => rect.left)),\n right: Math.max(...rects.map((rect) => rect.right)),\n top: Math.min(...rects.map((rect) => rect.top)),\n bottom: Math.max(...rects.map((rect) => rect.bottom)),\n };\n};\n\n// A control group pulls a wrapped button out of its wrapper by negative margins, so the menu lines up with the button.\nconst offsetToVisibleBox = (node: HTMLElement) => ({\n name: \"offset\",\n options: {\n offset: ({ placement }: { placement: Placement }): [number, number] => {\n if (triggerOf(node) === node) {\n return [0, 0];\n }\n\n const wrapper = node.getBoundingClientRect();\n const box = visibleBoxOf(node);\n const [side, align] = placement.split(\"-\");\n const vertical = side === \"top\" || side === \"bottom\";\n const start = vertical ? \"left\" : \"top\";\n const end = vertical ? \"right\" : \"bottom\";\n const skidding =\n align === \"start\"\n ? box[start] - wrapper[start]\n : align === \"end\"\n ? box[end] - wrapper[end]\n : (box[start] + box[end] - wrapper[start] - wrapper[end]) / 2;\n const distance = {\n bottom: box.bottom - wrapper.bottom,\n top: wrapper.top - box.top,\n right: box.right - wrapper.right,\n left: wrapper.left - box.left,\n }[side];\n\n return [skidding, distance ?? 0];\n },\n },\n});\n\nconst TABBABLE =\n 'a[href], button, input, select, textarea, iframe, [tabindex], [contenteditable=\"true\"]';\n\n// A menu opened with the pointer hands the focus back without a focus ring, so its trigger does not stay lit.\nconst returnFocusOptions = (visible: boolean) =>\n ({ focusVisible: visible } as FocusOptions);\n\n// Moves the focus where a Tab or Shift+Tab on the trigger would go. The closing menu itself does not count.\nconst focusTabNeighbor = (\n trigger: HTMLElement,\n step: 1 | -1,\n menu: HTMLElement | null\n) => {\n const nodes = Array.from(\n document.querySelectorAll<HTMLElement>(TABBABLE)\n ).filter(\n (node) =>\n node === trigger ||\n (node.tabIndex >= 0 &&\n !(node as HTMLButtonElement).disabled &&\n !node.closest(\"[inert]\") &&\n !menu?.contains(node))\n );\n\n const from = nodes.indexOf(trigger);\n\n for (\n let index = from + step;\n from !== -1 && index >= 0 && index < nodes.length;\n index += step\n ) {\n nodes[index].focus(returnFocusOptions(true));\n\n if (document.activeElement === nodes[index]) {\n return nodes[index];\n }\n }\n\n return null;\n};\n\n// A press on a layer above the menu, such as a dialog it opened, never reached the old overlay either.\n// An open native dialog that does not hold the menu sits above it in the top layer.\nconst isOnLayerAbove = (\n target: EventTarget | null,\n own: HTMLElement | null\n) => {\n if (!(target instanceof Element) || !own) {\n return false;\n }\n\n const modalDialog = target.closest(\"dialog[open]\");\n\n if (modalDialog && !modalDialog.contains(own)) {\n return true;\n }\n\n const layer = target.closest<HTMLElement>(\".c-window\");\n\n if (!layer || layer === own) {\n return false;\n }\n\n const layerZ = Number(layer.style.zIndex) || 0;\n const ownZ = Number(own.style.zIndex) || 0;\n\n return (\n layerZ > ownZ ||\n (layerZ === ownZ &&\n Boolean(\n own.compareDocumentPosition(layer) & Node.DOCUMENT_POSITION_FOLLOWING\n ))\n );\n};\n\nconst PRERENDER_DELAY = 50;\nconst PRERENDER_GAP = 50;\nconst prerenderQueue: (() => void)[] = [];\nlet prerenderTimer: ReturnType<typeof setTimeout> | null = null;\n\nconst runPrerenderQueue = () => {\n prerenderQueue.shift()?.();\n prerenderTimer = prerenderQueue.length\n ? setTimeout(runPrerenderQueue, PRERENDER_GAP)\n : null;\n};\n\n// One menu at a time, a moment after the caller turns it on, so no frame carries more than one render.\nconst queuePrerender = (render: () => void) => {\n prerenderQueue.push(render);\n\n if (!prerenderTimer) {\n prerenderTimer = setTimeout(runPrerenderQueue, PRERENDER_DELAY);\n }\n\n return () => {\n const index = prerenderQueue.indexOf(render);\n\n if (index !== -1) {\n prerenderQueue.splice(index, 1);\n }\n };\n};\n\n// Its layout effect runs before the popper ref is set, so it finds the menu through its own node.\nconst FocusInside: FC<{ onFocused: () => void }> = ({ onFocused }) => {\n const ref = useRef<HTMLSpanElement>(null);\n\n useLayoutEffect(() => {\n const menu = ref.current?.parentElement;\n\n if (!menu) {\n return;\n }\n\n if (menu.contains(document.activeElement)) {\n onFocused();\n return;\n }\n\n const first = Array.from(menu.querySelectorAll<HTMLElement>(TABBABLE)).find(\n (node) => node.tabIndex >= 0 && !(node as HTMLButtonElement).disabled\n );\n\n (first ?? menu.closest<HTMLElement>(\"[tabindex]\"))?.focus({\n preventScroll: true,\n });\n onFocused();\n }, [onFocused]);\n\n return <span ref={ref} hidden />;\n};\n\nexport const Menu: FC<IMenu> = ({\n children,\n disableFocusLock = false,\n onMenuClick,\n handleScroll = true,\n mode = \"normal\",\n width,\n open: defaultOpen = false,\n onOpen,\n onClose,\n onBeforeClose,\n position = \"bottom-start\",\n target,\n className,\n menuClassName,\n popperClassName,\n backgroundElementClass,\n windowAbsolutelyPositioned = false,\n onPopperOpen,\n closeOnTab = false,\n prerender = false,\n scopedFocus = false,\n}) => {\n const [open, setOpen] = useState(defaultOpen);\n const [syncedOpen, setSyncedOpen] = useState(defaultOpen);\n const [exited, setExited] = useState(!defaultOpen);\n // The trigger node lives in a ref. In state it would render every menu of a list again right after it mounts.\n const elementRef = useRef<HTMLElement | null>(null);\n const isOpenAtLeastOnce = useRef(false);\n const wasOpen = useRef(open);\n const focusBeforeOpen = useRef<Element | null>(null);\n const focusWasVisible = useRef(false);\n const returnFocusTo = useRef<HTMLElement | null>(null);\n const popperRef = useRef<HTMLDivElement | null>(null);\n const windowRef = useRef<HTMLDivElement | null>(null);\n const tabOut = useRef<1 | -1 | 0>(0);\n\n if (defaultOpen !== syncedOpen) {\n setSyncedOpen(defaultOpen);\n setOpen(defaultOpen);\n }\n\n // Read on the render that opens the menu, before the focus lock moves the focus inside it.\n if (open && !wasOpen.current && typeof document !== \"undefined\") {\n focusBeforeOpen.current = document.activeElement;\n focusWasVisible.current = isFocusVisible(document.activeElement);\n }\n wasOpen.current = open;\n\n useEffect(() => {\n if (open) {\n setExited(false);\n }\n }, [open]);\n\n // Set on the node itself, so the trigger gets it also through a wrapper such as Tooltip. It runs after every\n // render, because the trigger node lives in a ref and a new node brings no render of its own.\n const expandedTrigger = useRef<HTMLElement | null>(null);\n const checkedTrigger = useRef<HTMLElement | null>(null);\n const triggerOwnsExpanded = useRef(false);\n\n useEffect(() => {\n const node = elementRef.current;\n\n if (!node) {\n return;\n }\n\n const trigger = triggerOf(node);\n\n // A trigger that renders its own aria-expanded keeps it, so the menu never clears its \"false\".\n if (checkedTrigger.current !== trigger) {\n checkedTrigger.current = trigger;\n triggerOwnsExpanded.current = trigger.hasAttribute(\"aria-expanded\");\n }\n\n if (!trigger.hasAttribute(\"aria-haspopup\")) {\n trigger.setAttribute(\"aria-haspopup\", \"true\");\n }\n\n if (triggerOwnsExpanded.current) {\n return;\n }\n\n if (open) {\n trigger.setAttribute(\"aria-expanded\", \"true\");\n expandedTrigger.current = trigger;\n } else if (expandedTrigger.current) {\n expandedTrigger.current.removeAttribute(\"aria-expanded\");\n expandedTrigger.current = null;\n }\n });\n\n const handleRef = useForkRef(target ? target.ref : undefined, elementRef);\n\n // The popper needs the node as state, so it is copied only while the menu shows, before the browser paints.\n const [childNode, setChildNode] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n const node = open || !exited ? elementRef.current : null;\n\n if (node !== childNode) {\n setChildNode(node);\n }\n }, [open, exited, childNode]);\n\n const popperModifiers = useMemo(\n () =>\n childNode instanceof HTMLElement\n ? [offsetToVisibleBox(childNode)]\n : undefined,\n [childNode]\n );\n\n const handleOpen = useCallback(\n (\n event: Pick<MouseEvent<Element>, \"preventDefault\" | \"stopPropagation\">\n ) => {\n event?.preventDefault();\n event?.stopPropagation();\n setOpen(true);\n typeof onOpen === \"function\" && onOpen();\n typeof target?.props?.onClick === \"function\" &&\n target.props.onClick(event);\n },\n [onOpen, target?.props]\n );\n\n const handleClose = useCallback(() => {\n if (typeof onBeforeClose === \"function\" && !onBeforeClose()) {\n return false;\n }\n setOpen(false);\n typeof onClose === \"function\" && onClose();\n\n return true;\n }, [onClose, onBeforeClose]);\n\n const handleTabOut = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== \"Tab\" || event.defaultPrevented) {\n return;\n }\n\n event.preventDefault();\n tabOut.current = event.shiftKey ? -1 : 1;\n\n if (!handleClose()) {\n tabOut.current = 0;\n }\n },\n [handleClose]\n );\n\n const childProps = {\n forceClose: handleClose,\n };\n\n const [focusedInside, setFocusedInside] = useState(false);\n const markFocusedInside = useCallback(() => setFocusedInside(true), []);\n\n useEffect(() => {\n if (!open) {\n setFocusedInside(false);\n }\n }, [open]);\n\n const [prerenderStep, setPrerenderStep] = useState<\n \"off\" | \"waiting\" | \"rendering\" | \"done\"\n >(\"off\");\n\n // The caller can turn it on later, for example once the form that holds the menu has finished opening.\n useEffect(() => {\n if (prerender && prerenderStep === \"off\") {\n setPrerenderStep(\"waiting\");\n }\n }, [prerender, prerenderStep]);\n\n useEffect(() => {\n if (prerenderStep === \"off\" || prerenderStep === \"done\") {\n return undefined;\n }\n\n if (prerenderStep === \"rendering\") {\n setPrerenderStep(\"done\");\n\n return undefined;\n }\n\n return queuePrerender(() => setPrerenderStep(\"rendering\"));\n }, [prerenderStep]);\n\n const handleCloseRef = useRef(handleClose);\n handleCloseRef.current = handleClose;\n\n const handleTargetClose = useCallback(\n (\n event: Pick<MouseEvent<Element>, \"preventDefault\" | \"stopPropagation\">\n ) => {\n event?.preventDefault();\n event?.stopPropagation();\n handleClose();\n },\n [handleClose]\n );\n\n const targetProps = {\n open,\n ref: handleRef,\n onClick: open ? handleTargetClose : handleOpen,\n };\n\n // React carries the press through portals, so a nested menu or dialog counts as inside.\n const pressInside = useRef<Event | null>(null);\n const markPressInside = useCallback((event: React.PointerEvent) => {\n pressInside.current = event.nativeEvent;\n }, []);\n\n useEffect(() => {\n if (!open) {\n return undefined;\n }\n\n const closeOnPressOutside = (event: Event) => {\n if (\n pressInside.current === event ||\n elementRef.current?.contains(event.target as Node) ||\n isOnLayerAbove(event.target, windowRef.current)\n ) {\n return;\n }\n\n handleCloseRef.current();\n };\n\n // Armed after the press that opened the menu has passed the document.\n const timer = setTimeout(() =>\n document.addEventListener(\"pointerdown\", closeOnPressOutside)\n );\n\n return () => {\n clearTimeout(timer);\n document.removeEventListener(\"pointerdown\", closeOnPressOutside);\n };\n }, [open]);\n\n // The open prop is synced while rendering and the focus returns in a layout effect, so a menu that closes in the same\n // update in which an item opens a dialog gives the focus back to its trigger before the dialog calls showModal, in a\n // later commit, wherever the dialog sits in the tree. The dialog then returns the focus to the trigger.\n useLayoutEffect(() => {\n if (open) {\n isOpenAtLeastOnce.current = true;\n } else if (!open && isOpenAtLeastOnce.current) {\n const previous = focusBeforeOpen.current;\n const step = tabOut.current;\n const tabbedTo =\n step && elementRef.current\n ? focusTabNeighbor(\n triggerOf(elementRef.current),\n step,\n windowRef.current\n )\n : null;\n\n tabOut.current = 0;\n\n if (tabbedTo) {\n returnFocusTo.current = tabbedTo;\n } else {\n const returnTo =\n previous instanceof HTMLElement && previous.isConnected\n ? previous\n : elementRef.current;\n\n returnFocusTo.current = returnTo;\n returnTo?.focus(returnFocusOptions(focusWasVisible.current));\n }\n isOpenAtLeastOnce.current = false;\n }\n }, [open]);\n\n // A fading menu is already closed. Its content can still reach for the focus, and would take it away\n // with it when it unmounts, so the focus goes straight back to where the menu returned it.\n useEffect(() => {\n if (open || exited) {\n return undefined;\n }\n\n const keepFocusOut = (event: FocusEvent) => {\n if (popperRef.current?.contains(event.target as Node)) {\n returnFocusTo.current?.focus(\n returnFocusOptions(focusWasVisible.current)\n );\n }\n };\n\n document.addEventListener(\"focusin\", keepFocusOut, true);\n\n return () => document.removeEventListener(\"focusin\", keepFocusOut, true);\n }, [open, exited]);\n\n return (\n <>\n {target && React.cloneElement(target, targetProps)}\n {prerenderStep === \"rendering\" && !open && exited ? (\n <Portal>\n <div hidden aria-hidden>\n <MenuContextProvider value={{ open: false, setOpen }}>\n {typeof children === \"function\" ? children(childProps) : children}\n </MenuContextProvider>\n </div>\n </Portal>\n ) : null}\n {open || !exited ? (\n <Window\n ref={windowRef}\n onClose={handleClose}\n onKeyDown={closeOnTab && open ? handleTabOut : undefined}\n // The lock returns the focus with the props of the render before it turns off, too late to skip a Tab.\n // The menu returns the focus itself, so a menu that closes on Tab leaves the lock out of it.\n disableReturnFocus={closeOnTab}\n disableScrollLock={!handleScroll || !open}\n isolateScroll\n // The menu returns the focus itself at once, so a late returnFocus cannot undo a caller's move.\n // With the focus already inside, the lock turns on without searching the page for a place to put it.\n disableFocusLock={\n disableFocusLock || !open || (scopedFocus && !focusedInside)\n }\n // A fading menu is already closed, so an escape pressed meanwhile belongs to the page behind it.\n disableCloseOnEsc={!open}\n onPointerDownCapture={markPressInside}\n // Only the overlay and the menu take the pointer, so the first click outside only closes the menu.\n style={{\n position: windowAbsolutelyPositioned ? \"absolute\" : \"fixed\",\n pointerEvents: \"none\",\n }}\n >\n {open ? (\n <Overlay\n className={backgroundElementClass}\n disableBackgroundColor\n // Closing on the click, not the press, keeps the whole click on the overlay.\n onClick={handleClose}\n tabIndex={-1}\n style={{ pointerEvents: \"auto\" }}\n />\n ) : null}\n <Popper\n ref={popperRef}\n anchorEl={childNode}\n open={childNode ? open : false}\n placement={position}\n className={popperClassName}\n tabIndex={-1}\n afterWrite={onPopperOpen}\n modifiers={popperModifiers}\n transition\n >\n {({ placement, transitionProps }) => (\n <Grow\n placement={placement}\n in={transitionProps?.in}\n onEnter={transitionProps?.onEnter}\n onExited={() => {\n setExited(true);\n transitionProps?.onExited?.();\n }}\n >\n <StyledMenu\n className={classnames(\n \"c-simple-menu__paper\",\n `c-simple-menu__${mode}`,\n menuClassName,\n className\n )}\n $mode={mode}\n onMouseDown={onMenuClick}\n style={{\n pointerEvents: open ? \"auto\" : \"none\",\n width:\n width === \"target\"\n ? elementRef.current?.offsetWidth\n : width,\n }}\n >\n <MenuContextProvider value={{ open, setOpen }}>\n {typeof children === \"function\"\n ? children(childProps)\n : children}\n </MenuContextProvider>\n {scopedFocus && open ? (\n <FocusInside onFocused={markFocusedInside} />\n ) : null}\n </StyledMenu>\n </Grow>\n )}\n </Popper>\n </Window>\n ) : null}\n </>\n );\n};\n\nMenu.displayName = \"Menu\";\n"],"mappings":"AAAA,OAAOA,KAAK,IACVC,MAAM,EAKNC,QAAQ,EACRC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,OAAO,QAGF,OAAO;AAGd,OAAOC,UAAU,MAAM,YAAY;AAEnC,SAASC,mBAAmB,QAAQ,WAAW;AAC/C,SAASC,UAAU,QAAQ,UAAU;AACrC,SAASC,MAAM,QAAQ,eAAe;AACtC,OAAOC,UAAU,MAAM,wBAAwB;AAC/C,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,IAAI,QAAQ,gBAAgB;AACrC,SAASC,MAAM,QAAQ,WAAW;;AAMlC;AACA;;AAiDA,MAAMC,cAAc,GAAIC,OAAuB,IAAK;EAClD,IAAI;IACF,OAAOC,OAAO,CAACD,OAAO,oBAAPA,OAAO,CAAEE,OAAO,CAAC,gBAAgB,CAAC,CAAC;EACpD,CAAC,CAAC,OAAAC,OAAA,EAAM;IACN,OAAO,KAAK;EACd;AACF,CAAC;AAED,MAAMC,OAAO,GAAG,kCAAkC;;AAElD;AACA,MAAMC,SAAS,GAAIC,IAAiB;EAAA,IAAAC,mBAAA;EAAA,OAClCD,IAAI,CAACJ,OAAO,CAACE,OAAO,CAAC,GACjBE,IAAI,IAAAC,mBAAA,GACJD,IAAI,CAACE,aAAa,CAAcJ,OAAO,CAAC,YAAAG,mBAAA,GAAID,IAAI;AAAA;AAEtD,MAAMG,YAAY,GAAIH,IAAiB,IAAK;EAC1C;EACA,MAAMI,KAAK,GAAG,CACZJ,IAAI,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EAAA,CAEH,CACF,CAAC,GACP,IACJ,CAAC;AAEP,CAAC;AAED7E,IAAI,CAAC4H,WAAW,GAAG,MAAM","ignoreList":[]}
@@ -25,7 +25,12 @@ export interface ModalRootProps extends Omit<HTMLAttributes<HTMLDialogElement>,
25
25
  * the dialog opens; a later change does not move the stack entry.
26
26
  */
27
27
  belowOpenSheets?: boolean;
28
- /** A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once. */
28
+ /**
29
+ * A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once.
30
+ * The content mounts once the dialog is open, a render after the dialog node, so an autoFocus field takes the focus;
31
+ * an owner effect in the opening commit sees no content. It mounts again on every open, also when the owner reopens
32
+ * the dialog from onClose, and loses its local state.
33
+ */
29
34
  children: ReactNode | ((transition: ModalRootTransition) => ReactNode);
30
35
  }
31
36
  export declare const ModalRoot: React.ForwardRefExoticComponent<ModalRootProps & React.RefAttributes<HTMLDialogElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"ModalRoot.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAEZ,cAAc,EAEd,UAAU,EAEV,SAAS,EAMV,MAAM,OAAO,CAAC;AAiBf,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE3D,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,cACf,SAAQ,IAAI,CACV,cAAc,CAAC,iBAAiB,CAAC,EACjC,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,CAC7C;IACD,IAAI,EAAE,OAAO,CAAC;IACd,qEAAqE;IACrE,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC1D,6HAA6H;IAC7H,gBAAgB,CAAC,EAAE,CACjB,MAAM,EAAE,sB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IAC3D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,qHAAqH;IACrH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,UAAU,EAAE,mBAAmB,KAAK,SAAS,CAAC,CAAC;CACxE;AAED,eAAO,MAAM,SAAS,0FAqZrB,CAAC"}
@@ -9,6 +9,19 @@ import { StyledModalRoot } from "./Styles";
9
9
  import { Portal, PortalContainerProvider } from "../../helpers";
10
10
  import { layers } from "../../utils/layers";
11
11
  import useForkRef from "../../utils/useForkRef";
12
+ const FOCUSABLE = "button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), [tabindex]";
13
+
14
+ // What showModal does for content that was not there yet: the first node that takes the focus gets it, so a
15
+ // disabled or hidden one is skipped as the browser skips it.
16
+ const focusFirstFocusable = (dialog, overlayRoot) => {
17
+ Array.from(dialog.querySelectorAll(FOCUSABLE)).some(candidate => {
18
+ if (overlayRoot != null && overlayRoot.contains(candidate)) {
19
+ return false;
20
+ }
21
+ candidate.focus();
22
+ return document.activeElement === candidate;
23
+ });
24
+ };
12
25
  export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
13
26
  let open = _ref.open,
14
27
  onRequestClose = _ref.onRequestClose,
@@ -44,6 +57,12 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
44
57
  setDialog(node);
45
58
  }, []);
46
59
  const handleRef = useForkRef(setDialogNode, ref);
60
+ // A closed dialog hides its content, and React focuses an autoFocus field while it mounts, so the content mounts
61
+ // only once showModal ran on this node.
62
+ const _useState3 = useState(null),
63
+ shownDialog = _useState3[0],
64
+ setShownDialog = _useState3[1];
65
+ const contentShown = dialog !== null && shownDialog === dialog;
47
66
  const hasTransition = typeof children === "function";
48
67
  const openRef = useRef(open);
49
68
  const pressStartedOnBackdrop = useRef(false);
@@ -121,6 +140,7 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
121
140
  closeDialog(dialogRef.current);
122
141
  }
123
142
  setMounted(false);
143
+ setShownDialog(null);
124
144
  onClose == null || onClose();
125
145
  }, [closeDialog, onClose]);
126
146
 
@@ -137,8 +157,22 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
137
157
  if (stackIdRef.current === undefined) {
138
158
  stackIdRef.current = pushModalRoot(overlayRootRef.current, suspensionRef.current, belowOpenSheets);
139
159
  }
160
+ setShownDialog(dialog);
140
161
  }, [open, dialog, belowOpenSheets]);
141
162
 
163
+ // showModal found no content to focus, so the dialog moves the focus in once the content is there, unless an
164
+ // autoFocus field took it. A dialog that opened suspended stays out of the way of the overlay above it.
165
+ useLayoutEffect(() => {
166
+ if (!contentShown || !dialog || areModalRootsSuspended()) {
167
+ return;
168
+ }
169
+ const focus = document.activeElement;
170
+ if (focus !== dialog && dialog.contains(focus)) {
171
+ return;
172
+ }
173
+ focusFirstFocusable(dialog, overlayRootRef.current);
174
+ }, [contentShown, dialog]);
175
+
142
176
  // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.
143
177
  // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the
144
178
  // opener: a dialog removed while open would leave it on the body.
@@ -276,6 +310,13 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
276
310
  if (!mounted) {
277
311
  return null;
278
312
  }
313
+ let content = null;
314
+ if (contentShown) {
315
+ content = typeof children === "function" ? children({
316
+ in: open,
317
+ onExited: handleExited
318
+ }) : children;
319
+ }
279
320
  return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(RemoveScroll, {
280
321
  forwardProps: true,
281
322
  ref: handleRef,
@@ -289,10 +330,7 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
289
330
  onKeyDown: handleKeyDown
290
331
  }), /*#__PURE__*/React.createElement(PortalContainerProvider, {
291
332
  value: getOverlayRoot
292
- }, typeof children === "function" ? children({
293
- in: open,
294
- onExited: handleExited
295
- }) : children), /*#__PURE__*/React.createElement("div", {
333
+ }, content), /*#__PURE__*/React.createElement("div", {
296
334
  ref: overlayRootRef,
297
335
  className: "c-modal-root__overlays"
298
336
  }))));
@@ -1 +1 @@
1
- {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","areModalRootsSuspended","isTopModalRoot","popModalRoot","pushModalRoot","StyledModalRoot","Portal","PortalContainerProvider","layers","useForkRef","ModalRoot","_ref","ref","open","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","_ref$disableReturnFoc","disableReturnFocus","_ref$belowOpenSheets","belowOpenSheets","children","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","dialog","setDialog","dialogRef","setDialogNode","node","current","handleRef","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","disableReturnFocusRef","closeDialog","focusInside","contains","document","activeElement","close","_document$activeEleme","blur","focusBeforeSuspendRef","suspensionRef","suspend","style","zIndex","String","cloud","show","resume","showModal","focus","HTMLElement","preventScroll","finishClose","undefined","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","defaultPrevented","key","target","body","querySelector","preventDefault","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","handleNativeClose","isConnected","handlePointerDown","currentTarget","handleClick","stopPropagation","_overlayRootRef$curre4","handleExited","createElement","forwardProps","enabled","noIsolation","_extends","value","in","onExited","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport {\n areModalRootsSuspended,\n isTopModalRoot,\n ModalRootSuspension,\n popModalRoot,\n pushModalRoot,\n} from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport { layers } from \"../../utils/layers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /** Closing leaves the focus off the element that had it before the dialog opened, also when the owner unmounts it */\n disableReturnFocus?: boolean;\n /**\n * The dialog counts as opened before the sheets that are open, so they move into its overlay root and stay above\n * it. For a page dialog that a sheet covers, such as an archive that opens a task, also when the dialog mounts after\n * the sheet on a reload. A sheet that sits in the page mounts its content again in the overlay root; one that sits\n * in another modal moves without remounting, also above a modal opened in between from outside the sheet. Read when\n * the dialog opens; a later change does not move the stack entry.\n */\n belowOpenSheets?: boolean;\n /** A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once. */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n disableReturnFocus = false,\n belowOpenSheets = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n const disableReturnFocusRef = useRef(disableReturnFocus);\n disableReturnFocusRef.current = disableReturnFocus;\n\n // close() gives the focus back to the element that had it before showModal when the focus is in the dialog, so\n // a dialog that leaves it there takes it off again. A focus outside, as in a sheet that left the overlay root,\n // stays where it is.\n const closeDialog = useCallback((node: HTMLDialogElement) => {\n const focusInside = node.contains(document.activeElement);\n node.close();\n\n if (disableReturnFocusRef.current && focusInside) {\n (document.activeElement as HTMLElement | null)?.blur();\n }\n }, []);\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n // While suspended the dialog is open without being modal, in the page instead of the top layer, so it keeps a\n // layer just under the overlay it was suspended for. A dismiss then would close it under that overlay.\n // The stack calls suspend once for an entry and resume at most once, so the suspension is the stack's state.\n const focusBeforeSuspendRef = useRef<Element | null>(null);\n const suspensionRef = useRef<ModalRootSuspension>({\n suspend: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n focusBeforeSuspendRef.current = node.contains(document.activeElement)\n ? document.activeElement\n : null;\n node.style.zIndex = String(layers.cloud - 1);\n\n if (node.open) {\n node.close();\n node.show();\n }\n },\n resume: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n node.style.zIndex = \"\";\n\n if (node.open) {\n node.close();\n node.showModal();\n }\n\n const focus = focusBeforeSuspendRef.current;\n focusBeforeSuspendRef.current = null;\n\n if (focus instanceof HTMLElement && node.contains(focus)) {\n focus.focus({ preventScroll: true });\n }\n },\n });\n\n const finishClose = useCallback(() => {\n // A dialog that closes while suspended leaves the stack before the resume, so it drops its layer here.\n if (dialogRef.current) {\n dialogRef.current.style.zIndex = \"\";\n }\n\n // Content that sits in the overlay root moves out before the dialog hides it.\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n if (dialogRef.current) {\n closeDialog(dialogRef.current);\n }\n setMounted(false);\n onClose?.();\n }, [closeDialog, onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it\n // is rendered and can get its scroll positions back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(\n overlayRootRef.current,\n suspensionRef.current,\n belowOpenSheets\n );\n }\n }, [open, dialog, belowOpenSheets]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the\n // opener: a dialog removed while open would leave it on the body.\n useLayoutEffect(\n () => () => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n\n if (dialog?.open) {\n closeDialog(dialog);\n }\n },\n [dialog, closeDialog]\n );\n\n useLayoutEffect(() => {\n if (!open && mounted && !hasTransition) {\n finishClose();\n }\n }, [open, mounted, hasTransition, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n if (areModalRootsSuspended()) {\n return;\n }\n\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (\n openRef.current &&\n dialog.isConnected &&\n !dialog.open &&\n !areModalRootsSuspended()\n ) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n // A click does not bubble on through the React tree, as from a legacy window: a confirmation rendered in a\n // clickable row would otherwise click the row as well. React listens at the portal's container, so a click\n // listener on document or window does not see a click inside the dialog either, as with the window.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n event.stopPropagation();\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <PortalContainerProvider value={getOverlayRoot}>\n {typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children}\n </PortalContainerProvider>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,sBAAsB,EACtBC,cAAc,EAEdC,YAAY,EACZC,aAAa,QACR,kBAAkB;AACzB,SAASC,eAAe,QAAQ,UAAU;AAC1C,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,eAAe;AAC/D,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,OAAOC,UAAU,MAAM,wBAAwB;AAyC/C,OAAO,MAAMC,SAAS,gBAAGjB,UAAU,CACjC,CAAAkB,IAAA,EAkBEC,GAAG,KACA;EAAA,IAjBDC,IAAI,GAAAF,IAAA,CAAJE,IAAI;IACJC,cAAc,GAAAH,IAAA,CAAdG,cAAc;IACdC,gBAAgB,GAAAJ,IAAA,CAAhBI,gBAAgB;IA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CACR,CAAC;AAEb,CACF,CAAC;AAEDlB,SAAS,CAACoG,WAAW,GAAG,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","areModalRootsSuspended","isTopModalRoot","popModalRoot","pushModalRoot","StyledModalRoot","Portal","PortalContainerProvider","layers","useForkRef","FOCUSABLE","focusFirstFocusable","dialog","overlayRoot","Array","from","querySelectorAll","some","candidate","contains","focus","document","activeElement","ModalRoot","_ref","ref","open","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","_ref$disableReturnFoc","disableReturnFocus","_ref$belowOpenSheets","belowOpenSheets","children","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","setDialog","dialogRef","setDialogNode","node","current","handleRef","_useState3","shownDialog","setShownDialog","contentShown","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","disableReturnFocusRef","closeDialog","focusInside","close","_document$activeEleme","blur","focusBeforeSuspendRef","suspensionRef","suspend","style","zIndex","String","cloud","show","resume","showModal","HTMLElement","preventScroll","finishClose","undefined","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","defaultPrevented","key","target","body","querySelector","preventDefault","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","handleNativeClose","isConnected","handlePointerDown","currentTarget","handleClick","stopPropagation","_overlayRootRef$curre4","handleExited","content","in","onExited","createElement","forwardProps","enabled","noIsolation","_extends","value","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport {\n areModalRootsSuspended,\n isTopModalRoot,\n ModalRootSuspension,\n popModalRoot,\n pushModalRoot,\n} from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport { layers } from \"../../utils/layers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nconst FOCUSABLE =\n \"button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), [tabindex]\";\n\n// What showModal does for content that was not there yet: the first node that takes the focus gets it, so a\n// disabled or hidden one is skipped as the browser skips it.\nconst focusFirstFocusable = (\n dialog: HTMLDialogElement,\n overlayRoot: HTMLElement | null\n) => {\n Array.from(dialog.querySelectorAll<HTMLElement>(FOCUSABLE)).some(\n (candidate) => {\n if (overlayRoot?.contains(candidate)) {\n return false;\n }\n\n candidate.focus();\n\n return document.activeElement === candidate;\n }\n );\n};\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /** Closing leaves the focus off the element that had it before the dialog opened, also when the owner unmounts it */\n disableReturnFocus?: boolean;\n /**\n * The dialog counts as opened before the sheets that are open, so they move into its overlay root and stay above\n * it. For a page dialog that a sheet covers, such as an archive that opens a task, also when the dialog mounts after\n * the sheet on a reload. A sheet that sits in the page mounts its content again in the overlay root; one that sits\n * in another modal moves without remounting, also above a modal opened in between from outside the sheet. Read when\n * the dialog opens; a later change does not move the stack entry.\n */\n belowOpenSheets?: boolean;\n /**\n * A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once.\n * The content mounts once the dialog is open, a render after the dialog node, so an autoFocus field takes the focus;\n * an owner effect in the opening commit sees no content. It mounts again on every open, also when the owner reopens\n * the dialog from onClose, and loses its local state.\n */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n disableReturnFocus = false,\n belowOpenSheets = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n // A closed dialog hides its content, and React focuses an autoFocus field while it mounts, so the content mounts\n // only once showModal ran on this node.\n const [shownDialog, setShownDialog] = useState<HTMLDialogElement | null>(\n null\n );\n const contentShown = dialog !== null && shownDialog === dialog;\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n const disableReturnFocusRef = useRef(disableReturnFocus);\n disableReturnFocusRef.current = disableReturnFocus;\n\n // close() gives the focus back to the element that had it before showModal when the focus is in the dialog, so\n // a dialog that leaves it there takes it off again. A focus outside, as in a sheet that left the overlay root,\n // stays where it is.\n const closeDialog = useCallback((node: HTMLDialogElement) => {\n const focusInside = node.contains(document.activeElement);\n node.close();\n\n if (disableReturnFocusRef.current && focusInside) {\n (document.activeElement as HTMLElement | null)?.blur();\n }\n }, []);\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n // While suspended the dialog is open without being modal, in the page instead of the top layer, so it keeps a\n // layer just under the overlay it was suspended for. A dismiss then would close it under that overlay.\n // The stack calls suspend once for an entry and resume at most once, so the suspension is the stack's state.\n const focusBeforeSuspendRef = useRef<Element | null>(null);\n const suspensionRef = useRef<ModalRootSuspension>({\n suspend: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n focusBeforeSuspendRef.current = node.contains(document.activeElement)\n ? document.activeElement\n : null;\n node.style.zIndex = String(layers.cloud - 1);\n\n if (node.open) {\n node.close();\n node.show();\n }\n },\n resume: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n node.style.zIndex = \"\";\n\n if (node.open) {\n node.close();\n node.showModal();\n }\n\n const focus = focusBeforeSuspendRef.current;\n focusBeforeSuspendRef.current = null;\n\n if (focus instanceof HTMLElement && node.contains(focus)) {\n focus.focus({ preventScroll: true });\n }\n },\n });\n\n const finishClose = useCallback(() => {\n // A dialog that closes while suspended leaves the stack before the resume, so it drops its layer here.\n if (dialogRef.current) {\n dialogRef.current.style.zIndex = \"\";\n }\n\n // Content that sits in the overlay root moves out before the dialog hides it.\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n if (dialogRef.current) {\n closeDialog(dialogRef.current);\n }\n setMounted(false);\n setShownDialog(null);\n onClose?.();\n }, [closeDialog, onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it\n // is rendered and can get its scroll positions back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(\n overlayRootRef.current,\n suspensionRef.current,\n belowOpenSheets\n );\n }\n\n setShownDialog(dialog);\n }, [open, dialog, belowOpenSheets]);\n\n // showModal found no content to focus, so the dialog moves the focus in once the content is there, unless an\n // autoFocus field took it. A dialog that opened suspended stays out of the way of the overlay above it.\n useLayoutEffect(() => {\n if (!contentShown || !dialog || areModalRootsSuspended()) {\n return;\n }\n\n const focus = document.activeElement;\n\n if (focus !== dialog && dialog.contains(focus)) {\n return;\n }\n\n focusFirstFocusable(dialog, overlayRootRef.current);\n }, [contentShown, dialog]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the\n // opener: a dialog removed while open would leave it on the body.\n useLayoutEffect(\n () => () => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n\n if (dialog?.open) {\n closeDialog(dialog);\n }\n },\n [dialog, closeDialog]\n );\n\n useLayoutEffect(() => {\n if (!open && mounted && !hasTransition) {\n finishClose();\n }\n }, [open, mounted, hasTransition, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n if (areModalRootsSuspended()) {\n return;\n }\n\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (\n openRef.current &&\n dialog.isConnected &&\n !dialog.open &&\n !areModalRootsSuspended()\n ) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n // A click does not bubble on through the React tree, as from a legacy window: a confirmation rendered in a\n // clickable row would otherwise click the row as well. React listens at the portal's container, so a click\n // listener on document or window does not see a click inside the dialog either, as with the window.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n event.stopPropagation();\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n let content: ReactNode = null;\n\n if (contentShown) {\n content =\n typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <PortalContainerProvider value={getOverlayRoot}>\n {content}\n </PortalContainerProvider>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,sBAAsB,EACtBC,cAAc,EAEdC,YAAY,EACZC,aAAa,QACR,kBAAkB;AACzB,SAASC,eAAe,QAAQ,UAAU;AAC1C,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,eAAe;AAC/D,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,OAAOC,UAAU,MAAM,wBAAwB;AAI/C,MAAMC,SAAS,GACb,0NAA0N;;AAE5N;AACA;AACA,MAAMC,mBAAmB,GAAGA,CAC1BC,MAAyB,EACzBC,WAA+B,KAC5B;EACHC,KAAK,CAACC,IAAI,CAACH,MAAM,CAACI,gBAAgB,CAAcN,SAAS,CAAC,CAAC,CAACO,IAAI,CAC7DC,SAAS,IAAK;IACb,IAAIL,WAAW,YAAXA,WAAW,CAAEM,QAAQ,CAACD,SAAS,CAAC,EAAE;MACpC,OAAO,KAAK;IACd;IAEAA,SAAS,CAACE,KAAK,CAAC,CAAC;IAEjB,OAAOC,QAAQ,CAACC,aAAa,KAAKJ,SAAS;EAC7C,CACF,CAAC;AACH,CAAC;AA4CD,OAAO,MAAMK,SAAS,gBAAG9B,UAAU,CACjC,CAAA+B,IAAA,EAkBEC,GAAG,KACA;EAAA,IAjBDC,IAAI,GAAAF,IAAA,CAAJE,IAAI;IACJC,cAAc,GAAAH,IAAA,CAAdG,cAAc;IACdC,gBAAgB,GAAAJ,IAAA,CAAhBI,gBAAgB;IAChBC,OAAO,GAAAL,IAAA,CAAPK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