@bigbinary/neetoui 5.2.9 → 5.2.11

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/index.cjs.js CHANGED
@@ -10697,14 +10697,13 @@ var UniqueArray = /*#__PURE__*/function () {
10697
10697
  }]);
10698
10698
  return UniqueArray;
10699
10699
  }();
10700
- var renderFocusOnFocusableElements = function renderFocusOnFocusableElements(ref) {
10700
+ var trapFocusOnFocusableElements = function trapFocusOnFocusableElements(ref) {
10701
10701
  var _ref$current, _ref$current2;
10702
- var shouldFocusFirstFocusableElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
10703
10702
  var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
10704
10703
  var firstFocusableElement = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelectorAll(focusableElements)[0];
10705
10704
  var focusableContent = ref === null || ref === void 0 ? void 0 : (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.querySelectorAll(focusableElements);
10706
10705
  var lastFocusableElement = focusableContent[(focusableContent === null || focusableContent === void 0 ? void 0 : focusableContent.length) - 1];
10707
- document.addEventListener("keydown", function (e) {
10706
+ var onKeyDown = function onKeyDown(e) {
10708
10707
  var isTabPressed = e.key === "Tab" || e.keyCode === 9;
10709
10708
  if (!isTabPressed) {
10710
10709
  return;
@@ -10720,8 +10719,16 @@ var renderFocusOnFocusableElements = function renderFocusOnFocusableElements(ref
10720
10719
  e.preventDefault();
10721
10720
  }
10722
10721
  }
10723
- });
10724
- if (!shouldFocusFirstFocusableElement) return;
10722
+ };
10723
+ document.addEventListener("keydown", onKeyDown);
10724
+ return function () {
10725
+ return document.removeEventListener("keydown", onKeyDown);
10726
+ };
10727
+ };
10728
+ var focusFirstFocusableElement = function focusFirstFocusableElement(ref) {
10729
+ var _ref$current3;
10730
+ var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
10731
+ var firstFocusableElement = ref === null || ref === void 0 ? void 0 : (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.querySelectorAll(focusableElements)[0];
10725
10732
  firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
10726
10733
  };
10727
10734
  var hideScrollAndAddMargin = function hideScrollAndAddMargin() {
@@ -17398,25 +17405,45 @@ var OverlayManager = /*#__PURE__*/function () {
17398
17405
  _classCallCheck$3(this, OverlayManager);
17399
17406
  this.overlays = [];
17400
17407
  this.previouslyFocusedElements = [];
17408
+ this.subscribers = new Set();
17401
17409
  this.add = this.add.bind(this);
17402
17410
  this.remove = this.remove.bind(this);
17403
17411
  this.isTopOverlay = this.isTopOverlay.bind(this);
17404
17412
  this.hasOverlays = this.hasOverlays.bind(this);
17405
17413
  this.getFinalFocusInOverlay = this.getFinalFocusInOverlay.bind(this);
17406
17414
  this.getTopMostOverlay = this.getTopMostOverlay.bind(this);
17415
+ this.subscribe = this.subscribe.bind(this);
17407
17416
  }
17408
17417
  _createClass$3(OverlayManager, [{
17418
+ key: "subscribe",
17419
+ value: function subscribe(callback) {
17420
+ var _this = this;
17421
+ this.subscribers.add(callback);
17422
+ return function () {
17423
+ return _this.subscribers["delete"](callback);
17424
+ };
17425
+ }
17426
+ }, {
17409
17427
  key: "add",
17410
17428
  value: function add(overlay, elementToFocus) {
17411
17429
  this.overlays.push(overlay);
17412
17430
  this.previouslyFocusedElements.push(elementToFocus);
17431
+ this.subscribers.forEach(function (subscriber) {
17432
+ return subscriber();
17433
+ });
17413
17434
  }
17414
17435
  }, {
17415
17436
  key: "remove",
17416
- value: function remove(overlay) {
17437
+ value: function remove(overlay, elementToFocus) {
17417
17438
  this.overlays = this.overlays.filter(function (_overlay) {
17418
17439
  return _overlay !== overlay;
17419
17440
  });
17441
+ this.previouslyFocusedElements = this.previouslyFocusedElements.filter(function (_elementToFocus) {
17442
+ return _elementToFocus !== elementToFocus;
17443
+ });
17444
+ this.subscribers.forEach(function (subscriber) {
17445
+ return subscriber();
17446
+ });
17420
17447
  }
17421
17448
  }, {
17422
17449
  key: "isTopOverlay",
@@ -17432,7 +17459,11 @@ var OverlayManager = /*#__PURE__*/function () {
17432
17459
  }, {
17433
17460
  key: "getFinalFocusInOverlay",
17434
17461
  value: function getFinalFocusInOverlay() {
17435
- return this.previouslyFocusedElements.pop();
17462
+ var finalFocus = this.previouslyFocusedElements.pop();
17463
+ this.subscribers.forEach(function (subscriber) {
17464
+ return subscriber();
17465
+ });
17466
+ return finalFocus;
17436
17467
  }
17437
17468
  }, {
17438
17469
  key: "getTopMostOverlay",
@@ -17475,9 +17506,8 @@ var useOverlay = function useOverlay(_ref) {
17475
17506
  if ((_initialFocusRef = initialFocusRef) !== null && _initialFocusRef !== void 0 && _initialFocusRef.current) {
17476
17507
  var _initialFocusRef2, _initialFocusRef2$cur;
17477
17508
  (_initialFocusRef2 = initialFocusRef) === null || _initialFocusRef2 === void 0 ? void 0 : (_initialFocusRef2$cur = _initialFocusRef2.current) === null || _initialFocusRef2$cur === void 0 ? void 0 : _initialFocusRef2$cur.focus();
17478
- renderFocusOnFocusableElements(overlayWrapper, false);
17479
17509
  } else {
17480
- renderFocusOnFocusableElements(overlayWrapper);
17510
+ focusFirstFocusableElement(overlayWrapper);
17481
17511
  }
17482
17512
  }
17483
17513
  };
@@ -17487,18 +17517,27 @@ var useOverlay = function useOverlay(_ref) {
17487
17517
  onClose === null || onClose === void 0 ? void 0 : onClose();
17488
17518
  }, [onClose]);
17489
17519
  useOnClickOutside(overlayWrapper, backdropRef, closeOnOutsideClick ? handleOverlayClose : noop$2);
17520
+ var isTopOverlay = React$5.useSyncExternalStore(manager.subscribe, function () {
17521
+ return manager.isTopOverlay(overlayWrapper);
17522
+ });
17490
17523
  useHotkeys("esc", function () {
17491
17524
  closeOnEsc && handleOverlayClose();
17492
17525
  }, [handleOverlayClose, closeOnEsc]);
17493
17526
  React$5.useEffect(function () {
17527
+ var cleanUp = noop$2;
17494
17528
  if (isOpen) {
17495
- if (hasTransitionCompleted) focusRequiredElementInOverlay();
17529
+ if (hasTransitionCompleted && isTopOverlay) {
17530
+ focusRequiredElementInOverlay();
17531
+ // Enable focus trap only for the topmost overlay
17532
+ cleanUp = trapFocusOnFocusableElements(overlayWrapper);
17533
+ }
17496
17534
  if (shouldHideScrollAndAddMargin) hideScrollAndAddMargin();
17497
17535
  }
17498
17536
  return function () {
17499
17537
  if (!manager.hasOverlays()) showScrollAndRemoveMargin();
17538
+ cleanUp();
17500
17539
  };
17501
- }, [isOpen, hasTransitionCompleted]);
17540
+ }, [isOpen, hasTransitionCompleted, isTopOverlay]);
17502
17541
  var setFocusField = function setFocusField(fieldRef) {
17503
17542
  if (!fieldRef) return;
17504
17543
  initialFocusRef = {
@@ -17519,7 +17558,7 @@ var useOverlayManager = function useOverlayManager(ref, isOpen) {
17519
17558
  manager.add(ref, elementToFocus);
17520
17559
  }
17521
17560
  return function () {
17522
- manager.remove(ref);
17561
+ manager.remove(ref, elementToFocus);
17523
17562
  };
17524
17563
  }, [isOpen, ref]);
17525
17564
  };
@@ -20231,14 +20270,17 @@ var Input$2 = /*#__PURE__*/React$5.forwardRef(function (_ref, ref) {
20231
20270
  });
20232
20271
  Input$2.displayName = "Input";
20233
20272
 
20234
- var _excluded$o = ["keyName", "className"];
20273
+ var _excluded$o = ["keyName", "className", "tooltipProps"];
20235
20274
  var Kbd = function Kbd(_ref) {
20236
20275
  var keyName = _ref.keyName,
20237
20276
  className = _ref.className,
20277
+ tooltipProps = _ref.tooltipProps,
20238
20278
  otherProps = _objectWithoutProperties$1(_ref, _excluded$o);
20239
- return /*#__PURE__*/React__default["default"].createElement("span", _extends$4({
20279
+ return /*#__PURE__*/React__default["default"].createElement(Tooltip, _extends$4({
20280
+ disabled: !tooltipProps
20281
+ }, tooltipProps), /*#__PURE__*/React__default["default"].createElement("span", _extends$4({
20240
20282
  className: classnames$1(["neeto-ui-kbd", className])
20241
- }, otherProps), keyName);
20283
+ }, otherProps), keyName));
20242
20284
  };
20243
20285
 
20244
20286
  function _arrayWithoutHoles$1(arr) {