From 2abd442c640103a62973ef9923b29f75f20427d7 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Wed, 24 Jun 2026 14:59:34 +0200 Subject: [PATCH] Fix combobox menu not closing after a selection (#39595) --- .../components/form_fields/combobox_field.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/components/form_fields/combobox_field.tsx b/app/javascript/mastodon/components/form_fields/combobox_field.tsx index 875b2421a3..9c7d259571 100644 --- a/app/javascript/mastodon/components/form_fields/combobox_field.tsx +++ b/app/javascript/mastodon/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); } } }