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

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
  /**
@@ -2679,6 +2680,7 @@ function getFocusableElements(element) {
2679
2680
  */
2680
2681
  function getFirstAndLastFocusable(parentElement) {
2681
2682
  const focusableElements = getFocusableElements(parentElement);
2683
+ console.log('focusableElements', focusableElements);
2682
2684
 
2683
2685
  // First non disabled element.
2684
2686
  const first = focusableElements[0];
@@ -2722,6 +2724,12 @@ function useFocusTrap(focusZoneElement, focusElement) {
2722
2724
  return;
2723
2725
  }
2724
2726
  const focusable = getFirstAndLastFocusable(focusZoneElement);
2727
+ console.log('data', {
2728
+ focusable,
2729
+ activeElement: document.activeElement,
2730
+ endOfFocusZone: !evt.shiftKey && document.activeElement === focusable.last,
2731
+ isInFocusZone: focusZoneElement.contains(document.activeElement)
2732
+ });
2725
2733
 
2726
2734
  // Prevent focus switch if no focusable available.
2727
2735
  if (!focusable.first) {
@@ -2735,6 +2743,7 @@ function useFocusTrap(focusZoneElement, focusElement) {
2735
2743
  !evt.shiftKey && document.activeElement === focusable.last ||
2736
2744
  // Previous focus is outside the focus zone
2737
2745
  !focusZoneElement.contains(document.activeElement)) {
2746
+ console.log('focus first');
2738
2747
  focusable.first.focus();
2739
2748
  evt.preventDefault();
2740
2749
  return;
@@ -6538,7 +6547,7 @@ function usePopoverStyle(_ref5) {
6538
6547
  };
6539
6548
  }
6540
6549
 
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"];
6550
+ 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
6551
 
6543
6552
  /**
6544
6553
  * Defines the props of the component.
@@ -6591,6 +6600,7 @@ const _InnerPopover = /*#__PURE__*/forwardRef((props, ref) => {
6591
6600
  boundaryRef,
6592
6601
  fitToAnchorWidth,
6593
6602
  fitWithinViewportHeight,
6603
+ focusTrapZoneElement,
6594
6604
  offset,
6595
6605
  placement,
6596
6606
  style,
@@ -6624,11 +6634,12 @@ const _InnerPopover = /*#__PURE__*/forwardRef((props, ref) => {
6624
6634
  anchorRef,
6625
6635
  parentElement
6626
6636
  }, popperElement);
6637
+ const focusZoneElement = (focusTrapZoneElement === null || focusTrapZoneElement === void 0 ? void 0 : focusTrapZoneElement.current) || (popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.current);
6627
6638
  useCallbackOnEscape(onClose, isOpen && closeOnEscape);
6628
6639
 
6629
6640
  /** Only set focus within if the focus trap is disabled as they interfere with one another. */
6630
6641
  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);
6642
+ useFocusTrap(withFocusTrap && isOpen && focusZoneElement, focusElement === null || focusElement === void 0 ? void 0 : focusElement.current);
6632
6643
  const clickAwayRefs = useRef([popoverRef, anchorRef]);
6633
6644
  const mergedRefs = useMergeRefs(setPopperElement, ref, popoverRef);
6634
6645
  return isOpen ? renderPopover( /*#__PURE__*/React.createElement(Component, _extends({}, forwardedProps, {