[Glitch] Fix combobox listbox not scrolling up when new suggestions have loaded
Port 8c0b777d776594b901208a4a10d3ef1f5c4ccb0d to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
5109b00bc0
commit
d45a4a2dc3
@ -3,6 +3,7 @@ import {
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useId,
|
||||
useMemo,
|
||||
useRef,
|
||||
@ -276,12 +277,6 @@ const ComboboxWithRef = <Item extends ComboboxItem, GroupKey extends string>(
|
||||
setShouldMenuOpen(false);
|
||||
}, []);
|
||||
|
||||
const resetHighlight = useCallback(() => {
|
||||
const firstItem = flatItems[0];
|
||||
const firstItemId = firstItem ? getItemId(firstItem) : null;
|
||||
setHighlightedItemId(firstItemId);
|
||||
}, [getItemId, flatItems]);
|
||||
|
||||
const highlightItem = useCallback((id: string | null) => {
|
||||
setHighlightedItemId(id);
|
||||
if (id) {
|
||||
@ -294,6 +289,19 @@ const ComboboxWithRef = <Item extends ComboboxItem, GroupKey extends string>(
|
||||
}
|
||||
}, []);
|
||||
|
||||
const resetHighlight = useCallback(() => {
|
||||
const firstItem = flatItems[0];
|
||||
const firstItemId = firstItem ? getItemId(firstItem) : null;
|
||||
highlightItem(firstItemId);
|
||||
}, [flatItems, getItemId, highlightItem]);
|
||||
|
||||
// Reset scroll & highlight when menu items change
|
||||
useEffect(() => {
|
||||
if (flatItems.length) {
|
||||
resetHighlight();
|
||||
}
|
||||
}, [flatItems, resetHighlight]);
|
||||
|
||||
const handleFocus: React.FocusEventHandler<HTMLInputElement> = useCallback(
|
||||
(e) => {
|
||||
if (openOnFocus) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user