@deque/cauldron-react 6.13.0 → 6.14.0-canary.1653ddc7
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { ButtonHTMLAttributes, Ref } from 'react';
|
|
1
|
+
import React, { type ButtonHTMLAttributes, type Ref } from 'react';
|
|
2
2
|
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
3
3
|
buttonRef?: Ref<HTMLButtonElement>;
|
|
4
|
-
variant?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'link' | 'tag';
|
|
4
|
+
variant?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'link' | 'tag' | 'badge';
|
|
5
5
|
thin?: boolean;
|
|
6
6
|
}
|
|
7
7
|
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
package/lib/index.js
CHANGED
|
@@ -1715,7 +1715,7 @@ var SkipLink = /** @class */ (function (_super) {
|
|
|
1715
1715
|
|
|
1716
1716
|
var Button = React.forwardRef(function (_a, ref) {
|
|
1717
1717
|
var _b = _a.variant, variant = _b === void 0 ? 'primary' : _b, thin = _a.thin, children = _a.children, className = _a.className, buttonRef = _a.buttonRef, other = tslib.__rest(_a, ["variant", "thin", "children", "className", "buttonRef"]);
|
|
1718
|
-
return (React__default["default"].createElement("button", tslib.__assign({ type:
|
|
1718
|
+
return (React__default["default"].createElement("button", tslib.__assign({ type: "button", className: classNames__default["default"](className, {
|
|
1719
1719
|
'Button--primary': variant === 'primary',
|
|
1720
1720
|
'Button--secondary': variant === 'secondary',
|
|
1721
1721
|
'Button--error': variant === 'error',
|
|
@@ -1723,7 +1723,8 @@ var Button = React.forwardRef(function (_a, ref) {
|
|
|
1723
1723
|
Link: variant === 'link',
|
|
1724
1724
|
Tag: variant === 'tag',
|
|
1725
1725
|
'Button--tag': variant === 'tag',
|
|
1726
|
-
'Button--thin': thin
|
|
1726
|
+
'Button--thin': thin,
|
|
1727
|
+
'Button--badge': variant === 'badge'
|
|
1727
1728
|
}), ref: ref || buttonRef }, other), children));
|
|
1728
1729
|
});
|
|
1729
1730
|
Button.displayName = 'Button';
|
|
@@ -1779,7 +1780,7 @@ function getAutoAlignment(placement) {
|
|
|
1779
1780
|
}
|
|
1780
1781
|
}
|
|
1781
1782
|
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"]);
|
|
1783
|
+
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
1784
|
var ref = useSharedRef(refProp);
|
|
1784
1785
|
var Component = as || 'div';
|
|
1785
1786
|
var _d = reactDom$1.useFloating({
|
|
@@ -1815,6 +1816,7 @@ var AnchoredOverlay = React.forwardRef(function (_a, refProp) {
|
|
|
1815
1816
|
}
|
|
1816
1817
|
}
|
|
1817
1818
|
});
|
|
1819
|
+
useFocusTrap(ref, !focusTrap ? { disabled: true } : focusTrapOptions);
|
|
1818
1820
|
React.useEffect(function () {
|
|
1819
1821
|
if (typeof onPlacementChange === 'function') {
|
|
1820
1822
|
onPlacementChange(placement);
|
|
@@ -3647,16 +3649,20 @@ var Listbox = React.forwardRef(function (_a, ref) {
|
|
|
3647
3649
|
});
|
|
3648
3650
|
});
|
|
3649
3651
|
setSelectedOptions(matchingOptions);
|
|
3650
|
-
|
|
3652
|
+
if (!activeOption) {
|
|
3653
|
+
setActiveOption(matchingOptions[0] || null);
|
|
3654
|
+
}
|
|
3651
3655
|
}
|
|
3652
3656
|
else {
|
|
3653
3657
|
var matchingOption = options.find(function (option) {
|
|
3654
3658
|
return optionMatchesValue(option, listboxValue);
|
|
3655
3659
|
});
|
|
3656
3660
|
setSelectedOptions(matchingOption ? [matchingOption] : []);
|
|
3657
|
-
|
|
3661
|
+
if (!activeOption) {
|
|
3662
|
+
setActiveOption(matchingOption || null);
|
|
3663
|
+
}
|
|
3658
3664
|
}
|
|
3659
|
-
}, [isControlled, options, value, defaultValue]);
|
|
3665
|
+
}, [isControlled, options, value, defaultValue, activeOption]);
|
|
3660
3666
|
React.useEffect(function () {
|
|
3661
3667
|
if (activeOption) {
|
|
3662
3668
|
onActiveChange === null || onActiveChange === void 0 ? void 0 : onActiveChange(activeOption);
|
|
@@ -3749,7 +3755,8 @@ var Listbox = React.forwardRef(function (_a, ref) {
|
|
|
3749
3755
|
}
|
|
3750
3756
|
}, [options, activeOption, navigation, handleSelect]);
|
|
3751
3757
|
var handleFocus = React.useCallback(function (event) {
|
|
3752
|
-
if (!activeOption
|
|
3758
|
+
if (!activeOption ||
|
|
3759
|
+
!options.some(function (option) { return option.element === activeOption.element; })) {
|
|
3753
3760
|
var firstOption = options.find(function (option) { return !isDisabledOption(option); });
|
|
3754
3761
|
// istanbul ignore else
|
|
3755
3762
|
if (firstOption) {
|
package/package.json
CHANGED