@lumx/react 3.6.7-alpha.3 → 3.6.7-alpha.5

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
@@ -794,6 +794,8 @@ interface PopoverProps extends GenericProps, HasTheme {
794
794
  placement?: Placement;
795
795
  /** Whether the popover should be rendered into a DOM node that exists outside the DOM hierarchy of the parent component. */
796
796
  usePortal?: boolean;
797
+ /** The element in which the focus trap should be set. Default to popover. */
798
+ focusTrapZoneElement?: RefObject<HTMLElement>;
797
799
  /** Z-axis position. */
798
800
  zIndex?: number;
799
801
  /** On close callback (on click away or Escape pressed). */
package/index.js CHANGED
@@ -2668,7 +2668,8 @@ const DISABLED_SELECTOR = `[hidden], [tabindex="-1"], [disabled]:not([disabled="
2668
2668
 
2669
2669
  const isNotDisabled = element => !element.matches(DISABLED_SELECTOR);
2670
2670
  function getFocusableElements(element) {
2671
- return Array.from(element.querySelectorAll(TABBABLE_ELEMENTS_SELECTOR)).filter(isNotDisabled);
2671
+ const focusableElements = element.shadowRoot ? getFocusableElements(element.shadowRoot) : Array.from(element.querySelectorAll(TABBABLE_ELEMENTS_SELECTOR)).filter(isNotDisabled);
2672
+ return focusableElements;
2672
2673
  }
2673
2674
 
2674
2675
  /**
@@ -2728,13 +2729,15 @@ function useFocusTrap(focusZoneElement, focusElement) {
2728
2729
  evt.preventDefault();
2729
2730
  return;
2730
2731
  }
2732
+ const activeElement = focusZoneElement.shadowRoot ? focusZoneElement.shadowRoot.activeElement : document.activeElement;
2733
+ console.log('active', activeElement);
2731
2734
  if (
2732
2735
  // No previous focus
2733
- !document.activeElement ||
2736
+ !activeElement ||
2734
2737
  // Previous focus is at the end of the focus zone.
2735
- !evt.shiftKey && document.activeElement === focusable.last ||
2738
+ !evt.shiftKey && activeElement === focusable.last ||
2736
2739
  // Previous focus is outside the focus zone
2737
- !focusZoneElement.contains(document.activeElement)) {
2740
+ !focusZoneElement.contains(activeElement)) {
2738
2741
  focusable.first.focus();
2739
2742
  evt.preventDefault();
2740
2743
  return;
@@ -2743,7 +2746,7 @@ function useFocusTrap(focusZoneElement, focusElement) {
2743
2746
  // Focus order reversed
2744
2747
  evt.shiftKey &&
2745
2748
  // Previous focus is at the start of the focus zone.
2746
- document.activeElement === focusable.first) {
2749
+ activeElement === focusable.first) {
2747
2750
  focusable.last.focus();
2748
2751
  evt.preventDefault();
2749
2752
  }
@@ -6538,7 +6541,7 @@ function usePopoverStyle(_ref5) {
6538
6541
  };
6539
6542
  }
6540
6543
 
6541
- const _excluded$m = ["anchorRef", "as", "children", "className", "closeOnClickAway", "closeOnEscape", "elevation", "focusElement", "hasArrow", "isOpen", "onClose", "parentElement", "usePortal", "focusAnchorOnClose", "withFocusTrap", "boundaryRef", "fitToAnchorWidth", "fitWithinViewportHeight", "offset", "placement", "style", "theme", "zIndex"];
6544
+ const _excluded$m = ["anchorRef", "as", "children", "className", "closeOnClickAway", "closeOnEscape", "elevation", "focusElement", "hasArrow", "isOpen", "onClose", "parentElement", "usePortal", "focusAnchorOnClose", "withFocusTrap", "boundaryRef", "fitToAnchorWidth", "fitWithinViewportHeight", "focusTrapZoneElement", "offset", "placement", "style", "theme", "zIndex"];
6542
6545
 
6543
6546
  /**
6544
6547
  * Defines the props of the component.
@@ -6591,6 +6594,7 @@ const _InnerPopover = /*#__PURE__*/forwardRef((props, ref) => {
6591
6594
  boundaryRef,
6592
6595
  fitToAnchorWidth,
6593
6596
  fitWithinViewportHeight,
6597
+ focusTrapZoneElement,
6594
6598
  offset,
6595
6599
  placement,
6596
6600
  style,
@@ -6624,11 +6628,12 @@ const _InnerPopover = /*#__PURE__*/forwardRef((props, ref) => {
6624
6628
  anchorRef,
6625
6629
  parentElement
6626
6630
  }, popperElement);
6631
+ const focusZoneElement = (focusTrapZoneElement === null || focusTrapZoneElement === void 0 ? void 0 : focusTrapZoneElement.current) || (popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.current);
6627
6632
  useCallbackOnEscape(onClose, isOpen && closeOnEscape);
6628
6633
 
6629
6634
  /** Only set focus within if the focus trap is disabled as they interfere with one another. */
6630
6635
  useFocus(focusElement === null || focusElement === void 0 ? void 0 : focusElement.current, !withFocusTrap && isOpen && isPositioned);
6631
- useFocusTrap(withFocusTrap && isOpen && (popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.current), focusElement === null || focusElement === void 0 ? void 0 : focusElement.current);
6636
+ useFocusTrap(withFocusTrap && isOpen && focusZoneElement, focusElement === null || focusElement === void 0 ? void 0 : focusElement.current);
6632
6637
  const clickAwayRefs = useRef([popoverRef, anchorRef]);
6633
6638
  const mergedRefs = useMergeRefs(setPopperElement, ref, popoverRef);
6634
6639
  return isOpen ? renderPopover( /*#__PURE__*/React.createElement(Component, _extends({}, forwardedProps, {