@lumx/react 3.6.7-alpha.6 → 3.6.7-alpha.7
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 +2 -0
- package/index.js +18 -9
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/popover/Popover.tsx +5 -1
- package/src/hooks/useFocusTrap.ts +16 -7
- package/src/utils/focus/getFirstAndLastFocusable.ts +1 -1
- package/src/utils/focus/getFocusableElements.ts +1 -1
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
|
@@ -2712,6 +2712,7 @@ function useFocusTrap(focusZoneElement, focusElement) {
|
|
|
2712
2712
|
if (!rootElement || !focusZoneElement) {
|
|
2713
2713
|
return undefined;
|
|
2714
2714
|
}
|
|
2715
|
+
const focusZoneElementOrShadowRoot = focusZoneElement.shadowRoot || focusZoneElement;
|
|
2715
2716
|
|
|
2716
2717
|
// Trap 'Tab' key down focus switch into the focus zone.
|
|
2717
2718
|
const trapTabFocusInFocusZone = evt => {
|
|
@@ -2721,20 +2722,26 @@ function useFocusTrap(focusZoneElement, focusElement) {
|
|
|
2721
2722
|
if (key !== 'Tab') {
|
|
2722
2723
|
return;
|
|
2723
2724
|
}
|
|
2724
|
-
const focusable = getFirstAndLastFocusable(
|
|
2725
|
+
const focusable = getFirstAndLastFocusable(focusZoneElementOrShadowRoot);
|
|
2725
2726
|
|
|
2726
2727
|
// Prevent focus switch if no focusable available.
|
|
2727
2728
|
if (!focusable.first) {
|
|
2728
2729
|
evt.preventDefault();
|
|
2729
2730
|
return;
|
|
2730
2731
|
}
|
|
2732
|
+
const activeElement = focusZoneElement.shadowRoot ? focusZoneElement.shadowRoot.activeElement : document.activeElement;
|
|
2733
|
+
console.log('data', {
|
|
2734
|
+
activeElement,
|
|
2735
|
+
focusable,
|
|
2736
|
+
focusZoneElementOrShadowRoot
|
|
2737
|
+
});
|
|
2731
2738
|
if (
|
|
2732
2739
|
// No previous focus
|
|
2733
|
-
!
|
|
2740
|
+
!activeElement ||
|
|
2734
2741
|
// Previous focus is at the end of the focus zone.
|
|
2735
|
-
!evt.shiftKey &&
|
|
2742
|
+
!evt.shiftKey && activeElement === focusable.last ||
|
|
2736
2743
|
// Previous focus is outside the focus zone
|
|
2737
|
-
!
|
|
2744
|
+
!focusZoneElementOrShadowRoot.contains(activeElement)) {
|
|
2738
2745
|
focusable.first.focus();
|
|
2739
2746
|
evt.preventDefault();
|
|
2740
2747
|
return;
|
|
@@ -2743,7 +2750,7 @@ function useFocusTrap(focusZoneElement, focusElement) {
|
|
|
2743
2750
|
// Focus order reversed
|
|
2744
2751
|
evt.shiftKey &&
|
|
2745
2752
|
// Previous focus is at the start of the focus zone.
|
|
2746
|
-
|
|
2753
|
+
activeElement === focusable.first) {
|
|
2747
2754
|
focusable.last.focus();
|
|
2748
2755
|
evt.preventDefault();
|
|
2749
2756
|
}
|
|
@@ -2754,7 +2761,7 @@ function useFocusTrap(focusZoneElement, focusElement) {
|
|
|
2754
2761
|
};
|
|
2755
2762
|
|
|
2756
2763
|
// SETUP:
|
|
2757
|
-
if (focusElement &&
|
|
2764
|
+
if (focusElement && focusZoneElementOrShadowRoot.contains(focusElement)) {
|
|
2758
2765
|
// Focus the given element.
|
|
2759
2766
|
focusElement.focus({
|
|
2760
2767
|
preventScroll: true
|
|
@@ -2762,7 +2769,7 @@ function useFocusTrap(focusZoneElement, focusElement) {
|
|
|
2762
2769
|
} else {
|
|
2763
2770
|
var _getFirstAndLastFocus;
|
|
2764
2771
|
// Focus the first focusable element in the zone.
|
|
2765
|
-
(_getFirstAndLastFocus = getFirstAndLastFocusable(
|
|
2772
|
+
(_getFirstAndLastFocus = getFirstAndLastFocusable(focusZoneElementOrShadowRoot).first) === null || _getFirstAndLastFocus === void 0 ? void 0 : _getFirstAndLastFocus.focus({
|
|
2766
2773
|
preventScroll: true
|
|
2767
2774
|
});
|
|
2768
2775
|
}
|
|
@@ -6538,7 +6545,7 @@ function usePopoverStyle(_ref5) {
|
|
|
6538
6545
|
};
|
|
6539
6546
|
}
|
|
6540
6547
|
|
|
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"];
|
|
6548
|
+
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
6549
|
|
|
6543
6550
|
/**
|
|
6544
6551
|
* Defines the props of the component.
|
|
@@ -6591,6 +6598,7 @@ const _InnerPopover = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
6591
6598
|
boundaryRef,
|
|
6592
6599
|
fitToAnchorWidth,
|
|
6593
6600
|
fitWithinViewportHeight,
|
|
6601
|
+
focusTrapZoneElement,
|
|
6594
6602
|
offset,
|
|
6595
6603
|
placement,
|
|
6596
6604
|
style,
|
|
@@ -6624,11 +6632,12 @@ const _InnerPopover = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
6624
6632
|
anchorRef,
|
|
6625
6633
|
parentElement
|
|
6626
6634
|
}, popperElement);
|
|
6635
|
+
const focusZoneElement = (focusTrapZoneElement === null || focusTrapZoneElement === void 0 ? void 0 : focusTrapZoneElement.current) || (popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.current);
|
|
6627
6636
|
useCallbackOnEscape(onClose, isOpen && closeOnEscape);
|
|
6628
6637
|
|
|
6629
6638
|
/** Only set focus within if the focus trap is disabled as they interfere with one another. */
|
|
6630
6639
|
useFocus(focusElement === null || focusElement === void 0 ? void 0 : focusElement.current, !withFocusTrap && isOpen && isPositioned);
|
|
6631
|
-
useFocusTrap(withFocusTrap && isOpen &&
|
|
6640
|
+
useFocusTrap(withFocusTrap && isOpen && focusZoneElement, focusElement === null || focusElement === void 0 ? void 0 : focusElement.current);
|
|
6632
6641
|
const clickAwayRefs = useRef([popoverRef, anchorRef]);
|
|
6633
6642
|
const mergedRefs = useMergeRefs(setPopperElement, ref, popoverRef);
|
|
6634
6643
|
return isOpen ? renderPopover( /*#__PURE__*/React.createElement(Component, _extends({}, forwardedProps, {
|