@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.
package/dist/index.js CHANGED
@@ -17396,10 +17396,14 @@
17396
17396
  _useState2 = _slicedToArray(_useState, 2),
17397
17397
  open = _useState2[0],
17398
17398
  setOpen = _useState2[1];
17399
- var _useState3 = React.useState(!defaultOpen),
17399
+ var _useState3 = React.useState(defaultOpen),
17400
17400
  _useState4 = _slicedToArray(_useState3, 2),
17401
- exited = _useState4[0],
17402
- setExited = _useState4[1];
17401
+ syncedOpen = _useState4[0],
17402
+ setSyncedOpen = _useState4[1];
17403
+ var _useState5 = React.useState(!defaultOpen),
17404
+ _useState6 = _slicedToArray(_useState5, 2),
17405
+ exited = _useState6[0],
17406
+ setExited = _useState6[1];
17403
17407
  // The trigger node lives in a ref. In state it would render every menu of a list again right after it mounts.
17404
17408
  var elementRef = React.useRef(null);
17405
17409
  var isOpenAtLeastOnce = React.useRef(false);
@@ -17410,6 +17414,10 @@
17410
17414
  var popperRef = React.useRef(null);
17411
17415
  var windowRef = React.useRef(null);
17412
17416
  var tabOut = React.useRef(0);
17417
+ if (defaultOpen !== syncedOpen) {
17418
+ setSyncedOpen(defaultOpen);
17419
+ setOpen(defaultOpen);
17420
+ }
17413
17421
 
17414
17422
  // Read on the render that opens the menu, before the focus lock moves the focus inside it.
17415
17423
  if (open && !wasOpen.current && typeof document !== "undefined") {
@@ -17417,13 +17425,6 @@
17417
17425
  focusWasVisible.current = isFocusVisible(document.activeElement);
17418
17426
  }
17419
17427
  wasOpen.current = open;
17420
-
17421
- // Layout effects, so a menu that closes in the same update in which an item opens a dialog gives the focus back to
17422
- // its trigger before the dialog calls showModal. The dialog then returns the focus to the trigger, not to an item
17423
- // that is gone.
17424
- React.useLayoutEffect(function () {
17425
- setOpen(defaultOpen);
17426
- }, [defaultOpen]);
17427
17428
  React.useEffect(function () {
17428
17429
  if (open) {
17429
17430
  setExited(false);
@@ -17464,10 +17465,10 @@
17464
17465
  var handleRef = useForkRef(target ? target.ref : undefined, elementRef);
17465
17466
 
17466
17467
  // The popper needs the node as state, so it is copied only while the menu shows, before the browser paints.
17467
- var _useState5 = React.useState(null),
17468
- _useState6 = _slicedToArray(_useState5, 2),
17469
- childNode = _useState6[0],
17470
- setChildNode = _useState6[1];
17468
+ var _useState7 = React.useState(null),
17469
+ _useState8 = _slicedToArray(_useState7, 2),
17470
+ childNode = _useState8[0],
17471
+ setChildNode = _useState8[1];
17471
17472
  React.useLayoutEffect(function () {
17472
17473
  var node = open || !exited ? elementRef.current : null;
17473
17474
  if (node !== childNode) {
@@ -17506,10 +17507,10 @@
17506
17507
  var childProps = {
17507
17508
  forceClose: handleClose
17508
17509
  };
17509
- var _useState7 = React.useState(false),
17510
- _useState8 = _slicedToArray(_useState7, 2),
17511
- focusedInside = _useState8[0],
17512
- setFocusedInside = _useState8[1];
17510
+ var _useState9 = React.useState(false),
17511
+ _useState0 = _slicedToArray(_useState9, 2),
17512
+ focusedInside = _useState0[0],
17513
+ setFocusedInside = _useState0[1];
17513
17514
  var markFocusedInside = React.useCallback(function () {
17514
17515
  return setFocusedInside(true);
17515
17516
  }, []);
@@ -17518,10 +17519,10 @@
17518
17519
  setFocusedInside(false);
17519
17520
  }
17520
17521
  }, [open]);
17521
- var _useState9 = React.useState("off"),
17522
- _useState0 = _slicedToArray(_useState9, 2),
17523
- prerenderStep = _useState0[0],
17524
- setPrerenderStep = _useState0[1];
17522
+ var _useState1 = React.useState("off"),
17523
+ _useState10 = _slicedToArray(_useState1, 2),
17524
+ prerenderStep = _useState10[0],
17525
+ setPrerenderStep = _useState10[1];
17525
17526
 
17526
17527
  // The caller can turn it on later, for example once the form that holds the menu has finished opening.
17527
17528
  React.useEffect(function () {
@@ -17580,6 +17581,10 @@
17580
17581
  document.removeEventListener("pointerdown", closeOnPressOutside);
17581
17582
  };
17582
17583
  }, [open]);
17584
+
17585
+ // The open prop is synced while rendering and the focus returns in a layout effect, so a menu that closes in the same
17586
+ // update in which an item opens a dialog gives the focus back to its trigger before the dialog calls showModal, in a
17587
+ // later commit, wherever the dialog sits in the tree. The dialog then returns the focus to the trigger.
17583
17588
  React.useLayoutEffect(function () {
17584
17589
  if (open) {
17585
17590
  isOpenAtLeastOnce.current = true;
@@ -19141,6 +19146,19 @@
19141
19146
  StyledModalRoot.displayName = "StyledModalRoot";
19142
19147
 
19143
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
+ };
19144
19162
  var ModalRoot = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
19145
19163
  var open = _ref.open,
19146
19164
  onRequestClose = _ref.onRequestClose,
@@ -19178,6 +19196,13 @@
19178
19196
  setDialog(node);
19179
19197
  }, []);
19180
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;
19181
19206
  var hasTransition = typeof children === "function";
19182
19207
  var openRef = React.useRef(open);
19183
19208
  var pressStartedOnBackdrop = React.useRef(false);
@@ -19257,6 +19282,7 @@
19257
19282
  closeDialog(dialogRef.current);
19258
19283
  }
19259
19284
  setMounted(false);
19285
+ setShownDialog(null);
19260
19286
  onClose === null || onClose === void 0 || onClose();
19261
19287
  }, [closeDialog, onClose]);
19262
19288
 
@@ -19273,8 +19299,22 @@
19273
19299
  if (stackIdRef.current === undefined) {
19274
19300
  stackIdRef.current = pushModalRoot(overlayRootRef.current, suspensionRef.current, belowOpenSheets);
19275
19301
  }
19302
+ setShownDialog(dialog);
19276
19303
  }, [open, dialog, belowOpenSheets]);
19277
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
+
19278
19318
  // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.
19279
19319
  // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the
19280
19320
  // opener: a dialog removed while open would leave it on the body.
@@ -19420,6 +19460,13 @@
19420
19460
  if (!mounted) {
19421
19461
  return null;
19422
19462
  }
19463
+ var content = null;
19464
+ if (contentShown) {
19465
+ content = typeof children === "function" ? children({
19466
+ in: open,
19467
+ onExited: handleExited
19468
+ }) : children;
19469
+ }
19423
19470
  return /*#__PURE__*/React__default["default"].createElement(Portal, null, /*#__PURE__*/React__default["default"].createElement(reactRemoveScroll.RemoveScroll, {
19424
19471
  forwardProps: true,
19425
19472
  ref: handleRef,
@@ -19433,10 +19480,7 @@
19433
19480
  onKeyDown: handleKeyDown
19434
19481
  }), /*#__PURE__*/React__default["default"].createElement(PortalContainerProvider, {
19435
19482
  value: getOverlayRoot
19436
- }, typeof children === "function" ? children({
19437
- in: open,
19438
- onExited: handleExited
19439
- }) : children), /*#__PURE__*/React__default["default"].createElement("div", {
19483
+ }, content), /*#__PURE__*/React__default["default"].createElement("div", {
19440
19484
  ref: overlayRootRef,
19441
19485
  className: "c-modal-root__overlays"
19442
19486
  }))));