react-magma-dom 4.7.0-next.8 → 4.7.0-next.9

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/esm/index.js CHANGED
@@ -9484,11 +9484,20 @@ function useFocusLock(active, header, body) {
9484
9484
  var focusableItems = useRef([]);
9485
9485
  var updateFocusableItems = function updateFocusableItems() {
9486
9486
  var _rootNode$current;
9487
- focusableItems.current = (_rootNode$current = rootNode.current) == null ? void 0 : _rootNode$current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"]), video');
9487
+ focusableItems.current = Array.from(((_rootNode$current = rootNode.current) == null ? void 0 : _rootNode$current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"]), video')) || []);
9488
9488
  };
9489
9489
  useEffect(function () {
9490
9490
  if (active) {
9491
9491
  updateFocusableItems();
9492
+ var observer = new MutationObserver(function () {
9493
+ updateFocusableItems();
9494
+ });
9495
+ if (rootNode.current) {
9496
+ observer.observe(rootNode.current, {
9497
+ childList: true,
9498
+ subtree: true
9499
+ });
9500
+ }
9492
9501
  if (header && header.current) {
9493
9502
  header.current.focus();
9494
9503
  } else if (focusableItems.current && focusableItems.current.length > 0) {
@@ -9498,21 +9507,11 @@ function useFocusLock(active, header, body) {
9498
9507
  body.current.firstChild.setAttribute('tabIndex', '-1');
9499
9508
  body.current.firstChild.focus();
9500
9509
  }
9510
+ return function () {
9511
+ observer.disconnect();
9512
+ };
9501
9513
  }
9502
- }, [active]);
9503
- useEffect(function () {
9504
- var observer = new MutationObserver(function () {
9505
- updateFocusableItems();
9506
- });
9507
- updateFocusableItems();
9508
- rootNode.current && observer.observe(rootNode.current, {
9509
- childList: true,
9510
- subtree: true
9511
- });
9512
- return function () {
9513
- observer.disconnect();
9514
- };
9515
- }, [rootNode]);
9514
+ }, [active, header, body]);
9516
9515
  useEffect(function () {
9517
9516
  var handleKeyPress = function handleKeyPress(event) {
9518
9517
  if (!focusableItems.current) return;
@@ -9554,7 +9553,7 @@ function useFocusLock(active, header, body) {
9554
9553
  return function () {
9555
9554
  window.removeEventListener('keydown', handleKeyPress);
9556
9555
  };
9557
- }, [active, focusableItems]);
9556
+ }, [active, focusableItems, header]);
9558
9557
  return rootNode;
9559
9558
  }
9560
9559