@deque/cauldron-react 6.13.0 → 6.14.0
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Placement } from '@floating-ui/dom';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import useFocusTrap from '../../utils/useFocusTrap';
|
|
3
4
|
declare const AnchoredOverlay: React.ForwardRefExoticComponent<{
|
|
4
5
|
/** A target element or ref to attach the overlay anchor element. */
|
|
5
6
|
target: HTMLElement | React.RefObject<HTMLElement> | React.MutableRefObject<HTMLElement>;
|
|
@@ -13,6 +14,10 @@ declare const AnchoredOverlay: React.ForwardRefExoticComponent<{
|
|
|
13
14
|
onPlacementChange?: ((placement: Placement) => void) | undefined;
|
|
14
15
|
/** An optional offset number to position the anchor element from its anchored target. */
|
|
15
16
|
offset?: number | undefined;
|
|
17
|
+
/** When set, traps focus within the AnchoredOverlay. */
|
|
18
|
+
focusTrap?: boolean | undefined;
|
|
19
|
+
/** When `focusTrap` is true, optional arguments to configure the focus trap. */
|
|
20
|
+
focusTrapOptions?: Parameters<typeof useFocusTrap>[1];
|
|
16
21
|
children?: React.ReactNode;
|
|
17
22
|
} & React.HTMLAttributes<HTMLElement> & {
|
|
18
23
|
as?: React.ElementType<any, keyof React.JSX.IntrinsicElements> | undefined;
|
package/lib/index.js
CHANGED
|
@@ -1779,7 +1779,7 @@ function getAutoAlignment(placement) {
|
|
|
1779
1779
|
}
|
|
1780
1780
|
}
|
|
1781
1781
|
var AnchoredOverlay = React.forwardRef(function (_a, refProp) {
|
|
1782
|
-
var as = _a.as, _b = _a.placement, initialPlacement = _b === void 0 ? 'auto' : _b, target = _a.target, children = _a.children, style = _a.style, _c = _a.open, open = _c === void 0 ? false : _c, offset = _a.offset, onOpenChange = _a.onOpenChange, onPlacementChange = _a.onPlacementChange, props = tslib.__rest(_a, ["as", "placement", "target", "children", "style", "open", "offset", "onOpenChange", "onPlacementChange"]);
|
|
1782
|
+
var as = _a.as, _b = _a.placement, initialPlacement = _b === void 0 ? 'auto' : _b, target = _a.target, children = _a.children, style = _a.style, _c = _a.open, open = _c === void 0 ? false : _c, offset = _a.offset, focusTrap = _a.focusTrap, focusTrapOptions = _a.focusTrapOptions, onOpenChange = _a.onOpenChange, onPlacementChange = _a.onPlacementChange, props = tslib.__rest(_a, ["as", "placement", "target", "children", "style", "open", "offset", "focusTrap", "focusTrapOptions", "onOpenChange", "onPlacementChange"]);
|
|
1783
1783
|
var ref = useSharedRef(refProp);
|
|
1784
1784
|
var Component = as || 'div';
|
|
1785
1785
|
var _d = reactDom$1.useFloating({
|
|
@@ -1815,6 +1815,7 @@ var AnchoredOverlay = React.forwardRef(function (_a, refProp) {
|
|
|
1815
1815
|
}
|
|
1816
1816
|
}
|
|
1817
1817
|
});
|
|
1818
|
+
useFocusTrap(ref, !focusTrap ? { disabled: true } : focusTrapOptions);
|
|
1818
1819
|
React.useEffect(function () {
|
|
1819
1820
|
if (typeof onPlacementChange === 'function') {
|
|
1820
1821
|
onPlacementChange(placement);
|
|
@@ -3647,16 +3648,20 @@ var Listbox = React.forwardRef(function (_a, ref) {
|
|
|
3647
3648
|
});
|
|
3648
3649
|
});
|
|
3649
3650
|
setSelectedOptions(matchingOptions);
|
|
3650
|
-
|
|
3651
|
+
if (!activeOption) {
|
|
3652
|
+
setActiveOption(matchingOptions[0] || null);
|
|
3653
|
+
}
|
|
3651
3654
|
}
|
|
3652
3655
|
else {
|
|
3653
3656
|
var matchingOption = options.find(function (option) {
|
|
3654
3657
|
return optionMatchesValue(option, listboxValue);
|
|
3655
3658
|
});
|
|
3656
3659
|
setSelectedOptions(matchingOption ? [matchingOption] : []);
|
|
3657
|
-
|
|
3660
|
+
if (!activeOption) {
|
|
3661
|
+
setActiveOption(matchingOption || null);
|
|
3662
|
+
}
|
|
3658
3663
|
}
|
|
3659
|
-
}, [isControlled, options, value, defaultValue]);
|
|
3664
|
+
}, [isControlled, options, value, defaultValue, activeOption]);
|
|
3660
3665
|
React.useEffect(function () {
|
|
3661
3666
|
if (activeOption) {
|
|
3662
3667
|
onActiveChange === null || onActiveChange === void 0 ? void 0 : onActiveChange(activeOption);
|
|
@@ -3749,7 +3754,8 @@ var Listbox = React.forwardRef(function (_a, ref) {
|
|
|
3749
3754
|
}
|
|
3750
3755
|
}, [options, activeOption, navigation, handleSelect]);
|
|
3751
3756
|
var handleFocus = React.useCallback(function (event) {
|
|
3752
|
-
if (!activeOption
|
|
3757
|
+
if (!activeOption ||
|
|
3758
|
+
!options.some(function (option) { return option.element === activeOption.element; })) {
|
|
3753
3759
|
var firstOption = options.find(function (option) { return !isDisabledOption(option); });
|
|
3754
3760
|
// istanbul ignore else
|
|
3755
3761
|
if (firstOption) {
|