@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/formik.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import React__default, { createContext, useContext, useRef, useEffect, useLayoutEffect, useCallback, useMemo, forwardRef as forwardRef$1, createElement, useState, cloneElement, Children, isValidElement, Fragment, Component, startTransition } from 'react';
2
+ import React__default, { createContext, useContext, useRef, useEffect, useLayoutEffect, useCallback, useMemo, forwardRef as forwardRef$1, createElement, useState, cloneElement, Children, isValidElement, useSyncExternalStore, Fragment, Component, startTransition } from 'react';
3
3
  import { useFormikContext, Field, Form as Form$1, Formik, useField } from 'formik';
4
4
  import { Link, useHistory } from 'react-router-dom';
5
5
  import ReactDOM, { createPortal } from 'react-dom';
@@ -16459,25 +16459,45 @@ var OverlayManager = /*#__PURE__*/function () {
16459
16459
  _classCallCheck$1(this, OverlayManager);
16460
16460
  this.overlays = [];
16461
16461
  this.previouslyFocusedElements = [];
16462
+ this.subscribers = new Set();
16462
16463
  this.add = this.add.bind(this);
16463
16464
  this.remove = this.remove.bind(this);
16464
16465
  this.isTopOverlay = this.isTopOverlay.bind(this);
16465
16466
  this.hasOverlays = this.hasOverlays.bind(this);
16466
16467
  this.getFinalFocusInOverlay = this.getFinalFocusInOverlay.bind(this);
16467
16468
  this.getTopMostOverlay = this.getTopMostOverlay.bind(this);
16469
+ this.subscribe = this.subscribe.bind(this);
16468
16470
  }
16469
16471
  _createClass$1(OverlayManager, [{
16472
+ key: "subscribe",
16473
+ value: function subscribe(callback) {
16474
+ var _this = this;
16475
+ this.subscribers.add(callback);
16476
+ return function () {
16477
+ return _this.subscribers["delete"](callback);
16478
+ };
16479
+ }
16480
+ }, {
16470
16481
  key: "add",
16471
16482
  value: function add(overlay, elementToFocus) {
16472
16483
  this.overlays.push(overlay);
16473
16484
  this.previouslyFocusedElements.push(elementToFocus);
16485
+ this.subscribers.forEach(function (subscriber) {
16486
+ return subscriber();
16487
+ });
16474
16488
  }
16475
16489
  }, {
16476
16490
  key: "remove",
16477
- value: function remove(overlay) {
16491
+ value: function remove(overlay, elementToFocus) {
16478
16492
  this.overlays = this.overlays.filter(function (_overlay) {
16479
16493
  return _overlay !== overlay;
16480
16494
  });
16495
+ this.previouslyFocusedElements = this.previouslyFocusedElements.filter(function (_elementToFocus) {
16496
+ return _elementToFocus !== elementToFocus;
16497
+ });
16498
+ this.subscribers.forEach(function (subscriber) {
16499
+ return subscriber();
16500
+ });
16481
16501
  }
16482
16502
  }, {
16483
16503
  key: "isTopOverlay",
@@ -16493,7 +16513,11 @@ var OverlayManager = /*#__PURE__*/function () {
16493
16513
  }, {
16494
16514
  key: "getFinalFocusInOverlay",
16495
16515
  value: function getFinalFocusInOverlay() {
16496
- return this.previouslyFocusedElements.pop();
16516
+ var finalFocus = this.previouslyFocusedElements.pop();
16517
+ this.subscribers.forEach(function (subscriber) {
16518
+ return subscriber();
16519
+ });
16520
+ return finalFocus;
16497
16521
  }
16498
16522
  }, {
16499
16523
  key: "getTopMostOverlay",
@@ -16569,14 +16593,13 @@ var hyphenize = function hyphenize(string) {
16569
16593
  }
16570
16594
  return fallbackString;
16571
16595
  };
16572
- var renderFocusOnFocusableElements = function renderFocusOnFocusableElements(ref) {
16596
+ var trapFocusOnFocusableElements = function trapFocusOnFocusableElements(ref) {
16573
16597
  var _ref$current, _ref$current2;
16574
- var shouldFocusFirstFocusableElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
16575
16598
  var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
16576
16599
  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];
16577
16600
  var focusableContent = ref === null || ref === void 0 ? void 0 : (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.querySelectorAll(focusableElements);
16578
16601
  var lastFocusableElement = focusableContent[(focusableContent === null || focusableContent === void 0 ? void 0 : focusableContent.length) - 1];
16579
- document.addEventListener("keydown", function (e) {
16602
+ var onKeyDown = function onKeyDown(e) {
16580
16603
  var isTabPressed = e.key === "Tab" || e.keyCode === 9;
16581
16604
  if (!isTabPressed) {
16582
16605
  return;
@@ -16592,8 +16615,16 @@ var renderFocusOnFocusableElements = function renderFocusOnFocusableElements(ref
16592
16615
  e.preventDefault();
16593
16616
  }
16594
16617
  }
16595
- });
16596
- if (!shouldFocusFirstFocusableElement) return;
16618
+ };
16619
+ document.addEventListener("keydown", onKeyDown);
16620
+ return function () {
16621
+ return document.removeEventListener("keydown", onKeyDown);
16622
+ };
16623
+ };
16624
+ var focusFirstFocusableElement = function focusFirstFocusableElement(ref) {
16625
+ var _ref$current3;
16626
+ var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
16627
+ 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];
16597
16628
  firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
16598
16629
  };
16599
16630
  var hideScrollAndAddMargin = function hideScrollAndAddMargin() {
@@ -16637,9 +16668,8 @@ var useOverlay = function useOverlay(_ref) {
16637
16668
  if ((_initialFocusRef = initialFocusRef) !== null && _initialFocusRef !== void 0 && _initialFocusRef.current) {
16638
16669
  var _initialFocusRef2, _initialFocusRef2$cur;
16639
16670
  (_initialFocusRef2 = initialFocusRef) === null || _initialFocusRef2 === void 0 ? void 0 : (_initialFocusRef2$cur = _initialFocusRef2.current) === null || _initialFocusRef2$cur === void 0 ? void 0 : _initialFocusRef2$cur.focus();
16640
- renderFocusOnFocusableElements(overlayWrapper, false);
16641
16671
  } else {
16642
- renderFocusOnFocusableElements(overlayWrapper);
16672
+ focusFirstFocusableElement(overlayWrapper);
16643
16673
  }
16644
16674
  }
16645
16675
  };
@@ -16649,18 +16679,27 @@ var useOverlay = function useOverlay(_ref) {
16649
16679
  onClose === null || onClose === void 0 ? void 0 : onClose();
16650
16680
  }, [onClose]);
16651
16681
  useOnClickOutside(overlayWrapper, backdropRef, closeOnOutsideClick ? handleOverlayClose : noop$1);
16682
+ var isTopOverlay = useSyncExternalStore(manager.subscribe, function () {
16683
+ return manager.isTopOverlay(overlayWrapper);
16684
+ });
16652
16685
  useHotkeys("esc", function () {
16653
16686
  closeOnEsc && handleOverlayClose();
16654
16687
  }, [handleOverlayClose, closeOnEsc]);
16655
16688
  useEffect(function () {
16689
+ var cleanUp = noop$1;
16656
16690
  if (isOpen) {
16657
- if (hasTransitionCompleted) focusRequiredElementInOverlay();
16691
+ if (hasTransitionCompleted && isTopOverlay) {
16692
+ focusRequiredElementInOverlay();
16693
+ // Enable focus trap only for the topmost overlay
16694
+ cleanUp = trapFocusOnFocusableElements(overlayWrapper);
16695
+ }
16658
16696
  if (shouldHideScrollAndAddMargin) hideScrollAndAddMargin();
16659
16697
  }
16660
16698
  return function () {
16661
16699
  if (!manager.hasOverlays()) showScrollAndRemoveMargin();
16700
+ cleanUp();
16662
16701
  };
16663
- }, [isOpen, hasTransitionCompleted]);
16702
+ }, [isOpen, hasTransitionCompleted, isTopOverlay]);
16664
16703
  var setFocusField = function setFocusField(fieldRef) {
16665
16704
  if (!fieldRef) return;
16666
16705
  initialFocusRef = {
@@ -16681,7 +16720,7 @@ var useOverlayManager = function useOverlayManager(ref, isOpen) {
16681
16720
  manager.add(ref, elementToFocus);
16682
16721
  }
16683
16722
  return function () {
16684
- manager.remove(ref);
16723
+ manager.remove(ref, elementToFocus);
16685
16724
  };
16686
16725
  }, [isOpen, ref]);
16687
16726
  };