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); } } }