@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.d.ts CHANGED
@@ -563,6 +563,7 @@ export type TypographyProps = {
563
563
  export type KbdProps = {
564
564
  keyName?: string;
565
565
  className?: string;
566
+ tooltipProps?: TooltipProps;
566
567
  };
567
568
 
568
569
  export type NoDataProps = {
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React$5 from 'react';
2
- import React__default, { createContext, useContext, useRef, useEffect, useLayoutEffect, useCallback, useMemo, forwardRef as forwardRef$1, createElement, useState, cloneElement as cloneElement$1, Children, isValidElement, Fragment, Component } from 'react';
2
+ import React__default, { createContext, useContext, useRef, useEffect, useLayoutEffect, useCallback, useMemo, forwardRef as forwardRef$1, createElement, useState, cloneElement as cloneElement$1, Children, isValidElement, useSyncExternalStore, Fragment, Component } from 'react';
3
3
  import { Right, Down, Close, Info, Focus, Left, Calendar, Check, MenuHorizontal, Clock, CheckCircle, Warning, CloseCircle } from '@bigbinary/neeto-icons';
4
4
  import { Link, NavLink, useHistory } from 'react-router-dom';
5
5
  import ReactDOM, { createPortal } from 'react-dom';
@@ -10667,14 +10667,13 @@ var UniqueArray = /*#__PURE__*/function () {
10667
10667
  }]);
10668
10668
  return UniqueArray;
10669
10669
  }();
10670
- var renderFocusOnFocusableElements = function renderFocusOnFocusableElements(ref) {
10670
+ var trapFocusOnFocusableElements = function trapFocusOnFocusableElements(ref) {
10671
10671
  var _ref$current, _ref$current2;
10672
- var shouldFocusFirstFocusableElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
10673
10672
  var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
10674
10673
  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];
10675
10674
  var focusableContent = ref === null || ref === void 0 ? void 0 : (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.querySelectorAll(focusableElements);
10676
10675
  var lastFocusableElement = focusableContent[(focusableContent === null || focusableContent === void 0 ? void 0 : focusableContent.length) - 1];
10677
- document.addEventListener("keydown", function (e) {
10676
+ var onKeyDown = function onKeyDown(e) {
10678
10677
  var isTabPressed = e.key === "Tab" || e.keyCode === 9;
10679
10678
  if (!isTabPressed) {
10680
10679
  return;
@@ -10690,8 +10689,16 @@ var renderFocusOnFocusableElements = function renderFocusOnFocusableElements(ref
10690
10689
  e.preventDefault();
10691
10690
  }
10692
10691
  }
10693
- });
10694
- if (!shouldFocusFirstFocusableElement) return;
10692
+ };
10693
+ document.addEventListener("keydown", onKeyDown);
10694
+ return function () {
10695
+ return document.removeEventListener("keydown", onKeyDown);
10696
+ };
10697
+ };
10698
+ var focusFirstFocusableElement = function focusFirstFocusableElement(ref) {
10699
+ var _ref$current3;
10700
+ var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
10701
+ 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];
10695
10702
  firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
10696
10703
  };
10697
10704
  var hideScrollAndAddMargin = function hideScrollAndAddMargin() {
@@ -17368,25 +17375,45 @@ var OverlayManager = /*#__PURE__*/function () {
17368
17375
  _classCallCheck$3(this, OverlayManager);
17369
17376
  this.overlays = [];
17370
17377
  this.previouslyFocusedElements = [];
17378
+ this.subscribers = new Set();
17371
17379
  this.add = this.add.bind(this);
17372
17380
  this.remove = this.remove.bind(this);
17373
17381
  this.isTopOverlay = this.isTopOverlay.bind(this);
17374
17382
  this.hasOverlays = this.hasOverlays.bind(this);
17375
17383
  this.getFinalFocusInOverlay = this.getFinalFocusInOverlay.bind(this);
17376
17384
  this.getTopMostOverlay = this.getTopMostOverlay.bind(this);
17385
+ this.subscribe = this.subscribe.bind(this);
17377
17386
  }
17378
17387
  _createClass$3(OverlayManager, [{
17388
+ key: "subscribe",
17389
+ value: function subscribe(callback) {
17390
+ var _this = this;
17391
+ this.subscribers.add(callback);
17392
+ return function () {
17393
+ return _this.subscribers["delete"](callback);
17394
+ };
17395
+ }
17396
+ }, {
17379
17397
  key: "add",
17380
17398
  value: function add(overlay, elementToFocus) {
17381
17399
  this.overlays.push(overlay);
17382
17400
  this.previouslyFocusedElements.push(elementToFocus);
17401
+ this.subscribers.forEach(function (subscriber) {
17402
+ return subscriber();
17403
+ });
17383
17404
  }
17384
17405
  }, {
17385
17406
  key: "remove",
17386
- value: function remove(overlay) {
17407
+ value: function remove(overlay, elementToFocus) {
17387
17408
  this.overlays = this.overlays.filter(function (_overlay) {
17388
17409
  return _overlay !== overlay;
17389
17410
  });
17411
+ this.previouslyFocusedElements = this.previouslyFocusedElements.filter(function (_elementToFocus) {
17412
+ return _elementToFocus !== elementToFocus;
17413
+ });
17414
+ this.subscribers.forEach(function (subscriber) {
17415
+ return subscriber();
17416
+ });
17390
17417
  }
17391
17418
  }, {
17392
17419
  key: "isTopOverlay",
@@ -17402,7 +17429,11 @@ var OverlayManager = /*#__PURE__*/function () {
17402
17429
  }, {
17403
17430
  key: "getFinalFocusInOverlay",
17404
17431
  value: function getFinalFocusInOverlay() {
17405
- return this.previouslyFocusedElements.pop();
17432
+ var finalFocus = this.previouslyFocusedElements.pop();
17433
+ this.subscribers.forEach(function (subscriber) {
17434
+ return subscriber();
17435
+ });
17436
+ return finalFocus;
17406
17437
  }
17407
17438
  }, {
17408
17439
  key: "getTopMostOverlay",
@@ -17445,9 +17476,8 @@ var useOverlay = function useOverlay(_ref) {
17445
17476
  if ((_initialFocusRef = initialFocusRef) !== null && _initialFocusRef !== void 0 && _initialFocusRef.current) {
17446
17477
  var _initialFocusRef2, _initialFocusRef2$cur;
17447
17478
  (_initialFocusRef2 = initialFocusRef) === null || _initialFocusRef2 === void 0 ? void 0 : (_initialFocusRef2$cur = _initialFocusRef2.current) === null || _initialFocusRef2$cur === void 0 ? void 0 : _initialFocusRef2$cur.focus();
17448
- renderFocusOnFocusableElements(overlayWrapper, false);
17449
17479
  } else {
17450
- renderFocusOnFocusableElements(overlayWrapper);
17480
+ focusFirstFocusableElement(overlayWrapper);
17451
17481
  }
17452
17482
  }
17453
17483
  };
@@ -17457,18 +17487,27 @@ var useOverlay = function useOverlay(_ref) {
17457
17487
  onClose === null || onClose === void 0 ? void 0 : onClose();
17458
17488
  }, [onClose]);
17459
17489
  useOnClickOutside(overlayWrapper, backdropRef, closeOnOutsideClick ? handleOverlayClose : noop$2);
17490
+ var isTopOverlay = useSyncExternalStore(manager.subscribe, function () {
17491
+ return manager.isTopOverlay(overlayWrapper);
17492
+ });
17460
17493
  useHotkeys("esc", function () {
17461
17494
  closeOnEsc && handleOverlayClose();
17462
17495
  }, [handleOverlayClose, closeOnEsc]);
17463
17496
  useEffect(function () {
17497
+ var cleanUp = noop$2;
17464
17498
  if (isOpen) {
17465
- if (hasTransitionCompleted) focusRequiredElementInOverlay();
17499
+ if (hasTransitionCompleted && isTopOverlay) {
17500
+ focusRequiredElementInOverlay();
17501
+ // Enable focus trap only for the topmost overlay
17502
+ cleanUp = trapFocusOnFocusableElements(overlayWrapper);
17503
+ }
17466
17504
  if (shouldHideScrollAndAddMargin) hideScrollAndAddMargin();
17467
17505
  }
17468
17506
  return function () {
17469
17507
  if (!manager.hasOverlays()) showScrollAndRemoveMargin();
17508
+ cleanUp();
17470
17509
  };
17471
- }, [isOpen, hasTransitionCompleted]);
17510
+ }, [isOpen, hasTransitionCompleted, isTopOverlay]);
17472
17511
  var setFocusField = function setFocusField(fieldRef) {
17473
17512
  if (!fieldRef) return;
17474
17513
  initialFocusRef = {
@@ -17489,7 +17528,7 @@ var useOverlayManager = function useOverlayManager(ref, isOpen) {
17489
17528
  manager.add(ref, elementToFocus);
17490
17529
  }
17491
17530
  return function () {
17492
- manager.remove(ref);
17531
+ manager.remove(ref, elementToFocus);
17493
17532
  };
17494
17533
  }, [isOpen, ref]);
17495
17534
  };
@@ -20201,14 +20240,17 @@ var Input$2 = /*#__PURE__*/forwardRef$1(function (_ref, ref) {
20201
20240
  });
20202
20241
  Input$2.displayName = "Input";
20203
20242
 
20204
- var _excluded$o = ["keyName", "className"];
20243
+ var _excluded$o = ["keyName", "className", "tooltipProps"];
20205
20244
  var Kbd = function Kbd(_ref) {
20206
20245
  var keyName = _ref.keyName,
20207
20246
  className = _ref.className,
20247
+ tooltipProps = _ref.tooltipProps,
20208
20248
  otherProps = _objectWithoutProperties$1(_ref, _excluded$o);
20209
- return /*#__PURE__*/React__default.createElement("span", _extends$4({
20249
+ return /*#__PURE__*/React__default.createElement(Tooltip, _extends$4({
20250
+ disabled: !tooltipProps
20251
+ }, tooltipProps), /*#__PURE__*/React__default.createElement("span", _extends$4({
20210
20252
  className: classnames$1(["neeto-ui-kbd", className])
20211
- }, otherProps), keyName);
20253
+ }, otherProps), keyName));
20212
20254
  };
20213
20255
 
20214
20256
  function _arrayWithoutHoles$1(arr) {