Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a07d13

Browse files
committed
fix: scroll item list into view when opening MultiSelectCombobox
1 parent 854f3c0 commit 3a07d13

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

site/src/components/MultiSelectCombobox/MultiSelectCombobox.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export const MultiSelectCombobox = forwardRef<
216216
const [onScrollbar, setOnScrollbar] = useState(false);
217217
const [isLoading, setIsLoading] = useState(false);
218218
const dropdownRef = useRef<HTMLDivElement>(null);
219+
const listRef = useRef<HTMLDivElement>(null);
219220

220221
const [selected, setSelected] = useState<Option[]>(
221222
arrayDefaultOptions ?? [],
@@ -364,6 +365,15 @@ export const MultiSelectCombobox = forwardRef<
364365
void exec();
365366
}, [debouncedSearchTerm, groupBy, open, triggerSearchOnFocus, onSearch]);
366367

368+
// Scroll dropdown into view on open
369+
useEffect(() => {
370+
if (!open || !listRef.current) {
371+
return;
372+
}
373+
374+
listRef.current.scrollIntoView({ behavior: "smooth" });
375+
}, [open]);
376+
367377
const CreatableItem = () => {
368378
if (!creatable) {
369379
return undefined;
@@ -603,7 +613,7 @@ export const MultiSelectCombobox = forwardRef<
603613
</div>
604614
</div>
605615
</div>
606-
<div className="relative">
616+
<div className="relative" ref={listRef}>
607617
{open && (
608618
<CommandList
609619
className={`absolute top-1 z-10 w-full rounded-md

0 commit comments

Comments
 (0)