lecom-ui 5.3.70 → 5.3.71
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.
|
@@ -92,11 +92,14 @@ const ComboboxItemContent = ({
|
|
|
92
92
|
const checkIconSize = CHECK_ICON_SIZES[size];
|
|
93
93
|
const isDisabled = option.disabled || false;
|
|
94
94
|
const textColor = isDisabled ? "text-grey-400" : "text-grey-800";
|
|
95
|
+
const isSelected = option.value === value;
|
|
95
96
|
return /* @__PURE__ */ React.createElement(
|
|
96
97
|
CommandItem,
|
|
97
98
|
{
|
|
98
99
|
key: option.value,
|
|
99
100
|
onSelect: handleSelect,
|
|
101
|
+
"data-combobox-value": option.value,
|
|
102
|
+
tabIndex: isSelected ? 0 : -1,
|
|
100
103
|
className: cn(
|
|
101
104
|
comboboxItemVariants({
|
|
102
105
|
size,
|
|
@@ -260,6 +263,7 @@ function Combobox({
|
|
|
260
263
|
}) {
|
|
261
264
|
const [open, setOpen] = React.useState(false);
|
|
262
265
|
const [search, setSearch] = React.useState("");
|
|
266
|
+
const commandListRef = React.useRef(null);
|
|
263
267
|
const filteredOptions = React.useMemo(
|
|
264
268
|
() => !search ? options : filterComboboxOptions(options, search),
|
|
265
269
|
[options, search]
|
|
@@ -273,6 +277,19 @@ function Combobox({
|
|
|
273
277
|
const handleClose = React.useCallback(() => {
|
|
274
278
|
setOpen(false);
|
|
275
279
|
}, []);
|
|
280
|
+
React.useEffect(() => {
|
|
281
|
+
if (!open) return;
|
|
282
|
+
if (!value) return;
|
|
283
|
+
requestAnimationFrame(() => {
|
|
284
|
+
const el = commandListRef.current?.querySelector(
|
|
285
|
+
`[data-combobox-value="${value}"]`
|
|
286
|
+
);
|
|
287
|
+
if (el) {
|
|
288
|
+
el.focus();
|
|
289
|
+
el.scrollIntoView({ block: "nearest" });
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}, [open, value]);
|
|
276
293
|
React.useEffect(() => {
|
|
277
294
|
if (!open) {
|
|
278
295
|
setSearch("");
|
|
@@ -310,6 +327,7 @@ function Combobox({
|
|
|
310
327
|
), /* @__PURE__ */ React.createElement(
|
|
311
328
|
CommandList,
|
|
312
329
|
{
|
|
330
|
+
ref: commandListRef,
|
|
313
331
|
key: search,
|
|
314
332
|
className: cn(
|
|
315
333
|
"max-h-44 overflow-y-auto overflow-x-hidden",
|