From c66654325c0e84df3fb7f665ee973ed1b835beb1 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Wed, 24 Jun 2026 14:59:34 +0200 Subject: [PATCH] [Glitch] Fix combobox menu not closing after a selection Port 724cac9a557651ad5a71fb744b387ccca1f47ae4 to glitch-soc Signed-off-by: Claire --- .../glitch/components/form_fields/combobox_field.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 da68d31504..a1d66c30a9 100644 --- a/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx +++ b/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx @@ -239,6 +239,11 @@ const ComboboxWithRef = ( const inputRef = useRef(); const popoverRef = useRef(null); + // This ref tracks whether the menu was just closed following a + // selection, and prevents the menu from re-opening again + // when focus is returned to the input. + const wasMenuJustClosedRef = useRef(false); + const [highlightedItemId, setHighlightedItemId] = useState( null, ); @@ -304,7 +309,7 @@ const ComboboxWithRef = ( const handleFocus: React.FocusEventHandler = useCallback( (e) => { - if (openOnFocus) { + if (openOnFocus && !wasMenuJustClosedRef.current) { setShouldMenuOpen(true); } onFocus?.(e); @@ -341,6 +346,10 @@ const ComboboxWithRef = ( if (closeOnSelect) { closeMenu(); + wasMenuJustClosedRef.current = true; + setTimeout(() => { + wasMenuJustClosedRef.current = false; + }, 50); } } }