@activecollab/components 2.0.548 → 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.
@@ -24,6 +24,19 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
24
24
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
25
25
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
26
26
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
27
+ var 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]";
28
+
29
+ // What showModal does for content that was not there yet: the first node that takes the focus gets it, so a
30
+ // disabled or hidden one is skipped as the browser skips it.
31
+ var focusFirstFocusable = function focusFirstFocusable(dialog, overlayRoot) {
32
+ Array.from(dialog.querySelectorAll(FOCUSABLE)).some(function (candidate) {
33
+ if (overlayRoot !== null && overlayRoot !== void 0 && overlayRoot.contains(candidate)) {
34
+ return false;
35
+ }
36
+ candidate.focus();
37
+ return document.activeElement === candidate;
38
+ });
39
+ };
27
40
  var ModalRoot = exports.ModalRoot = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
28
41
  var open = _ref.open,
29
42
  onRequestClose = _ref.onRequestClose,
@@ -61,6 +74,13 @@ var ModalRoot = exports.ModalRoot = /*#__PURE__*/(0, _react.forwardRef)(function
61
74
  setDialog(node);
62
75
  }, []);
63
76
  var handleRef = (0, _useForkRef.default)(setDialogNode, ref);
77
+ // A closed dialog hides its content, and React focuses an autoFocus field while it mounts, so the content mounts
78
+ // only once showModal ran on this node.
79
+ var _useState5 = (0, _react.useState)(null),
80
+ _useState6 = _slicedToArray(_useState5, 2),
81
+ shownDialog = _useState6[0],
82
+ setShownDialog = _useState6[1];
83
+ var contentShown = dialog !== null && shownDialog === dialog;
64
84
  var hasTransition = typeof children === "function";
65
85
  var openRef = (0, _react.useRef)(open);
66
86
  var pressStartedOnBackdrop = (0, _react.useRef)(false);
@@ -140,6 +160,7 @@ var ModalRoot = exports.ModalRoot = /*#__PURE__*/(0, _react.forwardRef)(function
140
160
  closeDialog(dialogRef.current);
141
161
  }
142
162
  setMounted(false);
163
+ setShownDialog(null);
143
164
  onClose === null || onClose === void 0 || onClose();
144
165
  }, [closeDialog, onClose]);
145
166
 
@@ -156,8 +177,22 @@ var ModalRoot = exports.ModalRoot = /*#__PURE__*/(0, _react.forwardRef)(function
156
177
  if (stackIdRef.current === undefined) {
157
178
  stackIdRef.current = (0, _modalRootStack.pushModalRoot)(overlayRootRef.current, suspensionRef.current, belowOpenSheets);
158
179
  }
180
+ setShownDialog(dialog);
159
181
  }, [open, dialog, belowOpenSheets]);
160
182
 
183
+ // showModal found no content to focus, so the dialog moves the focus in once the content is there, unless an
184
+ // autoFocus field took it. A dialog that opened suspended stays out of the way of the overlay above it.
185
+ (0, _react.useLayoutEffect)(function () {
186
+ if (!contentShown || !dialog || (0, _modalRootStack.areModalRootsSuspended)()) {
187
+ return;
188
+ }
189
+ var focus = document.activeElement;
190
+ if (focus !== dialog && dialog.contains(focus)) {
191
+ return;
192
+ }
193
+ focusFirstFocusable(dialog, overlayRootRef.current);
194
+ }, [contentShown, dialog]);
195
+
161
196
  // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.
162
197
  // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the
163
198
  // opener: a dialog removed while open would leave it on the body.
@@ -303,6 +338,13 @@ var ModalRoot = exports.ModalRoot = /*#__PURE__*/(0, _react.forwardRef)(function
303
338
  if (!mounted) {
304
339
  return null;
305
340
  }
341
+ var content = null;
342
+ if (contentShown) {
343
+ content = typeof children === "function" ? children({
344
+ in: open,
345
+ onExited: handleExited
346
+ }) : children;
347
+ }
306
348
  return /*#__PURE__*/_react.default.createElement(_helpers.Portal, null, /*#__PURE__*/_react.default.createElement(_reactRemoveScroll.RemoveScroll, {
307
349
  forwardProps: true,
308
350
  ref: handleRef,
@@ -316,10 +358,7 @@ var ModalRoot = exports.ModalRoot = /*#__PURE__*/(0, _react.forwardRef)(function
316
358
  onKeyDown: handleKeyDown
317
359
  }), /*#__PURE__*/_react.default.createElement(_helpers.PortalContainerProvider, {
318
360
  value: getOverlayRoot
319
- }, typeof children === "function" ? children({
320
- in: open,
321
- onExited: handleExited
322
- }) : children), /*#__PURE__*/_react.default.createElement("div", {
361
+ }, content), /*#__PURE__*/_react.default.createElement("div", {
323
362
  ref: overlayRootRef,
324
363
  className: "c-modal-root__overlays"
325
364
  }))));
@@ -1 +1 @@
1
- {"version":3,"file":"ModalRoot.js","names":["_react","_interopRequireWildcard","require","_reactRemoveScroll","_classnames","_interopRequireDefault","_modalRootStack","_Styles","_helpers","_layers","_useForkRef","_excluded","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","_slicedToArray","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","a","_arrayLikeToArray","toString","slice","constructor","name","Array","from","test","l","Symbol","iterator","u","next","done","push","value","return","isArray","_objectWithoutProperties","_objectWithoutPropertiesLoose","getOwnPropertySymbols","indexOf","propertyIsEnumerable","ModalRoot","exports","forwardRef","_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","_useState","useState","_useState2","mounted","setMounted","_useState3","_useState4","dialog","setDialog","dialogRef","useRef","setDialogNode","useCallback","node","current","handleRef","useForkRef","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","disableReturnFocusRef","closeDialog","focusInside","contains","document","activeElement","close","_document$activeEleme","blur","focusBeforeSuspendRef","suspensionRef","suspend","style","zIndex","String","layers","cloud","show","resume","showModal","focus","HTMLElement","preventScroll","finishClose","undefined","popModalRoot","useLayoutEffect","pushModalRoot","dismissRef","reason","event","areModalRootsSuspended","blocked","useEffect","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","isTopModalRoot","defaultPrevented","key","target","body","querySelector","preventDefault","_dismissRef$current","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","_dismissRef$current2","handleNativeClose","isConnected","handlePointerDown","currentTarget","handleClick","_dismissRef$current3","stopPropagation","_overlayRootRef$curre4","_dismissRef$current4","handleExited","createElement","Portal","RemoveScroll","forwardProps","enabled","noIsolation","StyledModalRoot","classnames","PortalContainerProvider","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 </Sty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QAAA,CAAA0K,MAAM,qBACLlL,MAAA,CAAAc,OAAA,CAAAmK,aAAA,CAAC9K,kBAAA,CAAAgL,YAAY;IACXC,YAAY;IACZ5G,GAAG,EAAEoC,SAAU;IACfyE,OAAO,EAAE,CAACnG,iBAAkB;IAC5BoG,WAAW;EAAA,gBAEXtL,MAAA,CAAAc,OAAA,CAAAmK,aAAA,CAAC1K,OAAA,CAAAgL,eAAe,EAAAvJ,QAAA,KACV4D,IAAI;IACRJ,SAAS,EAAE,IAAAgG,mBAAU,EAAC,cAAc,EAAEhG,SAAS,CAAE;IACjD,cAAYf,IAAI,GAAG,MAAM,GAAG,SAAU;IACtCgB,aAAa,EAAEgF,iBAAkB;IACjC/E,OAAO,EAAEiF,WAAY;IACrBhF,SAAS,EAAE2D;EAAc,iBAEzBtJ,MAAA,CAAAc,OAAA,CAAAmK,aAAA,CAACzK,QAAA,CAAAiL,uBAAuB;IAAC7H,KAAK,EAAEuD;EAAe,GAC5C,OAAO5B,QAAQ,KAAK,UAAU,GAC3BA,QAAQ,CAAC;IAAEmG,EAAE,EAAEjH,IAAI;IAAEkH,QAAQ,EAAEX;EAAa,CAAC,CAAC,GAC9CzF,QACmB,CAAC,eAC1BvF,MAAA,CAAAc,OAAA,CAAAmK,aAAA;IAAKzG,GAAG,EAAE0C,cAAe;IAAC1B,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,CACR,CAAC;AAEb,CACF,CAAC;AAEDpB,SAAS,CAACwH,WAAW,GAAG,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"ModalRoot.js","names":["_react","_interopRequireWildcard","require","_reactRemoveScroll","_classnames","_interopRequireDefault","_modalRootStack","_Styles","_helpers","_layers","_useForkRef","_excluded","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","_slicedToArray","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","a","_arrayLikeToArray","toString","slice","constructor","name","Array","from","test","l","Symbol","iterator","u","next","done","push","value","return","isArray","_objectWithoutProperties","_objectWithoutPropertiesLoose","getOwnPropertySymbols","indexOf","propertyIsEnumerable","FOCUSABLE","focusFirstFocusable","dialog","overlayRoot","querySelectorAll","some","candidate","contains","focus","document","activeElement","ModalRoot","exports","forwardRef","_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","_useState","useState","_useState2","mounted","setMounted","_useState3","_useState4","setDialog","dialogRef","useRef","setDialogNode","useCallback","node","current","handleRef","useForkRef","_useState5","_useState6","shownDialog","setShownDialog","contentShown","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","disableReturnFocusRef","closeDialog","focusInside","close","_document$activeEleme","blur","focusBeforeSuspendRef","suspensionRef","suspend","style","zIndex","String","layers","cloud","show","resume","showModal","HTMLElement","preventScroll","finishClose","undefined","popModalRoot","useLayoutEffect","pushModalRoot","areModalRootsSuspended","dismissRef","reason","event","blocked","useEffect","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","isTopModalRoot","defaultPrevented","key","target","body","querySelector","preventDefault","_dismissRef$current","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","_dismissRef$current2","handleNativeClose","isConnected","handlePointerDown","currentTarget","handleClick","_dismissRef$current3","stopPropagation","_overlayRootRef$curre4","_dismissRef$current4","handleExited","content","in","onExited","createElement","Portal","RemoveScroll","forwardProps","enabled","noIsolation","StyledModalRoot","classnames","PortalContainerProvider","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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAaA,IAAAC,kBAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,eAAA,GAAAJ,OAAA;AAOA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAL,sBAAA,CAAAH,OAAA;AAAgD,IAAAS,SAAA;AAAA,SAAAN,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAf,uBAAA,YAAAA,wBAAAW,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,cAAAK,EAAA,I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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,sBAAsB,EAC9B,KAAK,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAClC,IAAI,CAAC;IACV,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB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AkB,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;IAChBC,OAAO,GAAAL,IAAA,CAAPK,OAAO;IAAAC,qBAAA,GAAAN,IAAA,CACPO,iBAAiB;IAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,KAAK,GAAAA,qBAAA;IAAAE,qBAAA,GAAAR,IAAA,CACzBS,sBAAsB;IAAt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CAAC;IAChC;EACF,CAAC,EACD,CAACb,SAAS,CACZ,CAAC;EAED,MAAMsE,YAAY,GAAG3G,WAAW,CAAC,MAAM;IACrC,IAAI,CAACmB,IAAI,EAAE;MACT6D,WAAW,CAAC,CAAC;IACf;EACF,CAAC,EAAE,CAAC7D,IAAI,EAAE6D,WAAW,CAAC,CAAC;EAEvB,IAAI,CAACtC,OAAO,EAAE;IACZ,OAAO,IAAI;EACb;EAEA,oBACE5C,KAAA,CAAA8G,aAAA,CAAChG,MAAM,qBACLd,KAAA,CAAA8G,aAAA,CAACvG,YAAY;IACXwG,YAAY;IACZ3F,GAAG,EAAEiC,SAAU;IACf2D,OAAO,EAAE,CAAClF,iBAAkB;IAC5BmF,WAAW;EAAA,gBAEXjH,KAAA,CAAA8G,aAAA,CAACjG,eAAe,EAAAqG,QAAA,KACV1E,IAAI;IACRJ,SAAS,EAAE5B,UAAU,CAAC,cAAc,EAAE4B,SAAS,CAAE;IACjD,cAAYf,IAAI,GAAG,MAAM,GAAG,SAAU;IACtCgB,aAAa,EAAEmE,iBAAkB;IACjClE,OAAO,EAAEoE,WAAY;IACrBnE,SAAS,EAAEiD;EAAc,iBAEzBxF,KAAA,CAAA8G,aAAA,CAAC/F,uBAAuB;IAACoG,KAAK,EAAExD;EAAe,GAC5C,OAAOxB,QAAQ,KAAK,UAAU,GAC3BA,QAAQ,CAAC;IAAEiF,EAAE,EAAE/F,IAAI;IAAEgG,QAAQ,EAAER;EAAa,CAAC,CAAC,GAC9C1E,QACmB,CAAC,eAC1BnC,KAAA,CAAA8G,aAAA;IAAK1F,GAAG,EAAEsC,cAAe;IAACtB,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,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,KAA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,YAAY;IACZ7F,GAAG,EAAEgC,SAAU;IACf8D,OAAO,EAAE,CAACpF,iBAAkB;IAC5BqF,WAAW;EAAA,gBAEXhI,KAAA,CAAA6H,aAAA,CAAChH,eAAe,EAAAoH,QAAA,KACV5E,IAAI;IACRJ,SAAS,EAAEzC,UAAU,CAAC,cAAc,EAAEyC,SAAS,CAAE;IACjD,cAAYf,IAAI,GAAG,MAAM,GAAG,SAAU;IACtCgB,aAAa,EAAEkE,iBAAkB;IACjCjE,OAAO,EAAEmE,WAAY;IACrBlE,SAAS,EAAEgD;EAAc,iBAEzBpG,KAAA,CAAA6H,aAAA,CAAC9G,uBAAuB;IAACmH,KAAK,EAAEvD;EAAe,GAC5C+C,OACsB,CAAC,eAC1B1H,KAAA,CAAA6H,aAAA;IAAK5F,GAAG,EAAEyC,cAAe;IAACzB,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,CACR,CAAC;AAEb,CACF,CAAC;AAEDlB,SAAS,CAACoG,WAAW,GAAG,WAAW","ignoreList":[]}
package/dist/index.js CHANGED
@@ -19146,6 +19146,19 @@
19146
19146
  StyledModalRoot.displayName = "StyledModalRoot";
19147
19147
 
19148
19148
  var _excluded$1P = ["open", "onRequestClose", "onDismissBlocked", "onClose", "disableCloseOnEsc", "disableBackgroundClick", "disableScrollLock", "disableReturnFocus", "belowOpenSheets", "children", "className", "onPointerDown", "onClick", "onKeyDown"];
19149
+ var 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]";
19150
+
19151
+ // What showModal does for content that was not there yet: the first node that takes the focus gets it, so a
19152
+ // disabled or hidden one is skipped as the browser skips it.
19153
+ var focusFirstFocusable = function focusFirstFocusable(dialog, overlayRoot) {
19154
+ Array.from(dialog.querySelectorAll(FOCUSABLE)).some(function (candidate) {
19155
+ if (overlayRoot !== null && overlayRoot !== void 0 && overlayRoot.contains(candidate)) {
19156
+ return false;
19157
+ }
19158
+ candidate.focus();
19159
+ return document.activeElement === candidate;
19160
+ });
19161
+ };
19149
19162
  var ModalRoot = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
19150
19163
  var open = _ref.open,
19151
19164
  onRequestClose = _ref.onRequestClose,
@@ -19183,6 +19196,13 @@
19183
19196
  setDialog(node);
19184
19197
  }, []);
19185
19198
  var handleRef = useForkRef(setDialogNode, ref);
19199
+ // A closed dialog hides its content, and React focuses an autoFocus field while it mounts, so the content mounts
19200
+ // only once showModal ran on this node.
19201
+ var _useState5 = React.useState(null),
19202
+ _useState6 = _slicedToArray(_useState5, 2),
19203
+ shownDialog = _useState6[0],
19204
+ setShownDialog = _useState6[1];
19205
+ var contentShown = dialog !== null && shownDialog === dialog;
19186
19206
  var hasTransition = typeof children === "function";
19187
19207
  var openRef = React.useRef(open);
19188
19208
  var pressStartedOnBackdrop = React.useRef(false);
@@ -19262,6 +19282,7 @@
19262
19282
  closeDialog(dialogRef.current);
19263
19283
  }
19264
19284
  setMounted(false);
19285
+ setShownDialog(null);
19265
19286
  onClose === null || onClose === void 0 || onClose();
19266
19287
  }, [closeDialog, onClose]);
19267
19288
 
@@ -19278,8 +19299,22 @@
19278
19299
  if (stackIdRef.current === undefined) {
19279
19300
  stackIdRef.current = pushModalRoot(overlayRootRef.current, suspensionRef.current, belowOpenSheets);
19280
19301
  }
19302
+ setShownDialog(dialog);
19281
19303
  }, [open, dialog, belowOpenSheets]);
19282
19304
 
19305
+ // showModal found no content to focus, so the dialog moves the focus in once the content is there, unless an
19306
+ // autoFocus field took it. A dialog that opened suspended stays out of the way of the overlay above it.
19307
+ React.useLayoutEffect(function () {
19308
+ if (!contentShown || !dialog || areModalRootsSuspended()) {
19309
+ return;
19310
+ }
19311
+ var focus = document.activeElement;
19312
+ if (focus !== dialog && dialog.contains(focus)) {
19313
+ return;
19314
+ }
19315
+ focusFirstFocusable(dialog, overlayRootRef.current);
19316
+ }, [contentShown, dialog]);
19317
+
19283
19318
  // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.
19284
19319
  // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the
19285
19320
  // opener: a dialog removed while open would leave it on the body.
@@ -19425,6 +19460,13 @@
19425
19460
  if (!mounted) {
19426
19461
  return null;
19427
19462
  }
19463
+ var content = null;
19464
+ if (contentShown) {
19465
+ content = typeof children === "function" ? children({
19466
+ in: open,
19467
+ onExited: handleExited
19468
+ }) : children;
19469
+ }
19428
19470
  return /*#__PURE__*/React__default["default"].createElement(Portal, null, /*#__PURE__*/React__default["default"].createElement(reactRemoveScroll.RemoveScroll, {
19429
19471
  forwardProps: true,
19430
19472
  ref: handleRef,
@@ -19438,10 +19480,7 @@
19438
19480
  onKeyDown: handleKeyDown
19439
19481
  }), /*#__PURE__*/React__default["default"].createElement(PortalContainerProvider, {
19440
19482
  value: getOverlayRoot
19441
- }, typeof children === "function" ? children({
19442
- in: open,
19443
- onExited: handleExited
19444
- }) : children), /*#__PURE__*/React__default["default"].createElement("div", {
19483
+ }, content), /*#__PURE__*/React__default["default"].createElement("div", {
19445
19484
  ref: overlayRootRef,
19446
19485
  className: "c-modal-root__overlays"
19447
19486
  }))));