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