@refraction-ui/react 0.3.2 → 0.3.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/dist/index.cjs +49 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10962,7 +10962,7 @@ var selectContentVariants = cva({
|
|
|
10962
10962
|
}
|
|
10963
10963
|
});
|
|
10964
10964
|
var selectItemVariants = cva({
|
|
10965
|
-
base: "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
10965
|
+
base: "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground hover:bg-accent hover:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
10966
10966
|
variants: {
|
|
10967
10967
|
selected: {
|
|
10968
10968
|
true: "bg-accent/50",
|
|
@@ -11076,8 +11076,47 @@ var SelectTrigger = React41__namespace.forwardRef(
|
|
|
11076
11076
|
);
|
|
11077
11077
|
SelectTrigger.displayName = "SelectTrigger";
|
|
11078
11078
|
var SelectContent = React41__namespace.forwardRef(
|
|
11079
|
-
({ className, children, ...props },
|
|
11080
|
-
const { open, contentId, triggerId } = React41__namespace.useContext(SelectContext);
|
|
11079
|
+
({ className, children, ...props }, forwardedRef) => {
|
|
11080
|
+
const { open, contentId, triggerId, setOpen } = React41__namespace.useContext(SelectContext);
|
|
11081
|
+
const containerRef = React41__namespace.useRef(null);
|
|
11082
|
+
const ref = React41__namespace.useCallback(
|
|
11083
|
+
(node) => {
|
|
11084
|
+
containerRef.current = node;
|
|
11085
|
+
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
11086
|
+
else if (forwardedRef) forwardedRef.current = node;
|
|
11087
|
+
},
|
|
11088
|
+
[forwardedRef]
|
|
11089
|
+
);
|
|
11090
|
+
React41__namespace.useEffect(() => {
|
|
11091
|
+
if (open && containerRef.current) {
|
|
11092
|
+
const firstOption = containerRef.current.querySelector('[role="option"]:not([aria-disabled="true"])');
|
|
11093
|
+
if (firstOption) {
|
|
11094
|
+
setTimeout(() => firstOption.focus(), 0);
|
|
11095
|
+
}
|
|
11096
|
+
}
|
|
11097
|
+
}, [open]);
|
|
11098
|
+
const handleKeyDown = (e) => {
|
|
11099
|
+
if (!containerRef.current) return;
|
|
11100
|
+
const options = Array.from(
|
|
11101
|
+
containerRef.current.querySelectorAll('[role="option"]:not([aria-disabled="true"])')
|
|
11102
|
+
);
|
|
11103
|
+
if (!options.length) return;
|
|
11104
|
+
const currentIndex = options.indexOf(document.activeElement);
|
|
11105
|
+
if (e.key === "ArrowDown") {
|
|
11106
|
+
e.preventDefault();
|
|
11107
|
+
const nextIndex = currentIndex < options.length - 1 ? currentIndex + 1 : 0;
|
|
11108
|
+
options[nextIndex]?.focus();
|
|
11109
|
+
} else if (e.key === "ArrowUp") {
|
|
11110
|
+
e.preventDefault();
|
|
11111
|
+
const prevIndex = currentIndex > 0 ? currentIndex - 1 : options.length - 1;
|
|
11112
|
+
options[prevIndex]?.focus();
|
|
11113
|
+
} else if (e.key === "Escape") {
|
|
11114
|
+
e.preventDefault();
|
|
11115
|
+
setOpen(false);
|
|
11116
|
+
const trigger = document.getElementById(triggerId);
|
|
11117
|
+
if (trigger) trigger.focus();
|
|
11118
|
+
}
|
|
11119
|
+
};
|
|
11081
11120
|
if (!open) return null;
|
|
11082
11121
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11083
11122
|
"div",
|
|
@@ -11088,6 +11127,8 @@ var SelectContent = React41__namespace.forwardRef(
|
|
|
11088
11127
|
role: "listbox",
|
|
11089
11128
|
"aria-labelledby": triggerId,
|
|
11090
11129
|
"data-state": open ? "open" : "closed",
|
|
11130
|
+
onKeyDown: handleKeyDown,
|
|
11131
|
+
tabIndex: -1,
|
|
11091
11132
|
...props,
|
|
11092
11133
|
children
|
|
11093
11134
|
}
|
|
@@ -11097,12 +11138,14 @@ var SelectContent = React41__namespace.forwardRef(
|
|
|
11097
11138
|
SelectContent.displayName = "SelectContent";
|
|
11098
11139
|
var SelectItem = React41__namespace.forwardRef(
|
|
11099
11140
|
({ className, children, value: itemValue, disabled: itemDisabled = false, ...props }, ref) => {
|
|
11100
|
-
const { value, onValueChange, setOpen } = React41__namespace.useContext(SelectContext);
|
|
11141
|
+
const { value, onValueChange, setOpen, triggerId } = React41__namespace.useContext(SelectContext);
|
|
11101
11142
|
const isSelected = value === itemValue;
|
|
11102
11143
|
const handleClick = () => {
|
|
11103
11144
|
if (!itemDisabled) {
|
|
11104
11145
|
onValueChange(itemValue);
|
|
11105
11146
|
setOpen(false);
|
|
11147
|
+
const trigger = document.getElementById(triggerId);
|
|
11148
|
+
if (trigger) setTimeout(() => trigger.focus(), 0);
|
|
11106
11149
|
}
|
|
11107
11150
|
};
|
|
11108
11151
|
const handleKeyDown = (e) => {
|
|
@@ -11110,6 +11153,8 @@ var SelectItem = React41__namespace.forwardRef(
|
|
|
11110
11153
|
e.preventDefault();
|
|
11111
11154
|
onValueChange(itemValue);
|
|
11112
11155
|
setOpen(false);
|
|
11156
|
+
const trigger = document.getElementById(triggerId);
|
|
11157
|
+
if (trigger) setTimeout(() => trigger.focus(), 0);
|
|
11113
11158
|
}
|
|
11114
11159
|
};
|
|
11115
11160
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|