From d45a4a2dc363ceb03cb8120496bffb09c881e0b4 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Wed, 24 Jun 2026 12:46:26 +0200 Subject: [PATCH] [Glitch] Fix combobox listbox not scrolling up when new suggestions have loaded Port 8c0b777d776594b901208a4a10d3ef1f5c4ccb0d to glitch-soc Signed-off-by: Claire --- .../components/form_fields/combobox_field.tsx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx b/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx index b856c4b32d..da68d31504 100644 --- a/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx +++ b/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx @@ -3,6 +3,7 @@ import { forwardRef, useCallback, useContext, + useEffect, useId, useMemo, useRef, @@ -276,12 +277,6 @@ const ComboboxWithRef = ( 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 = ( } }, []); + 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 = useCallback( (e) => { if (openOnFocus) {