Combobox: Fix list not being virtualized initially in some cases (#100188)

* Combobox: Set arbitrary initial max size

* Remove ?

* Set initial values to 0
This commit is contained in:
Tobias Skarhed 2025-02-06 17:34:52 +01:00 committed by GitHub
parent 1467d4b3e3
commit 677060862c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,7 +22,10 @@ export const useComboboxFloat = (items: Array<ComboboxOption<string | number>>,
const inputRef = useRef<HTMLInputElement>(null);
const floatingRef = useRef<HTMLDivElement>(null);
const scrollRef = useRef<HTMLDivElement>(null);
const [popoverMaxSize, setPopoverMaxSize] = useState<{ width: number; height: number } | undefined>(undefined);
const [popoverMaxSize, setPopoverMaxSize] = useState<{ width: number; height: number }>({
width: 0,
height: 0,
}); // set initial values to prevent infinite size, briefly removing the list virtualization
const scrollbarWidth = useMemo(() => getScrollbarWidth(), []);
@ -72,10 +75,10 @@ export const useComboboxFloat = (items: Array<ComboboxOption<string | number>>,
const floatStyles = {
...floatingStyles,
width: longestItemWidth,
maxWidth: popoverMaxSize?.width,
maxWidth: popoverMaxSize.width,
minWidth: inputRef.current?.offsetWidth,
maxHeight: popoverMaxSize?.height,
maxHeight: popoverMaxSize.height,
};
return { inputRef, floatingRef, scrollRef, floatStyles };