Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ui): keep filter search input focused when submenu is open (#2841)

gbirman0a41efa42e0a
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx
index 2bcc40ea2a..1b35b80ede 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/unified-filter-dropdown.tsx
@@ -13,6 +13,7 @@ import {
createSignal,
For,
type JSX,
+ onCleanup,
Show,
} from 'solid-js';
import SlidersHorizontalIcon from '@macro-icons/wide/sliders-horizontal.svg';
@@ -346,7 +347,41 @@ const SearchableFilterSubmenu = (props: {
if (props.onOpenChange) props.onOpenChange(v);
else setInternalOpen(v);
};
- let inputRef: HTMLInputElement | undefined;
+ const [inputRef, setInputRef] = createSignal<HTMLInputElement>();
+
+ // Focus the search input while the sub is open.
+ //
+ // Two issues conspire:
+ // 1. Initial focus has to wait for Kobalte's DismissableLayer to register
+ // itself as a nested layer of the parent menu (done in its onMount).
+ // The sub is portaled, so focusing the input before that registration
+ // looks like "focus outside" to the parent and closes the whole menu
+ // tree. One rAF is enough to get past those onMount callbacks.
+ // 2. After that, Kobalte's `onPointerMove` on the SubTrigger keeps
+ // calling `focusWithoutScrolling(e.currentTarget)` on every mouse
+ // move, stealing focus back to the trigger. Reclaim on blur — user
+ // dismissal routes (Escape / click-outside) close the sub first,
+ // which unregisters this listener before focus moves elsewhere.
+ createEffect(() => {
+ const el = inputRef();
+ if (!isOpen() || !el) return;
+
+ const raf = requestAnimationFrame(() => {
+ if (isOpen()) el.focus();
+ });
+
+ const onBlur = () => {
+ queueMicrotask(() => {
+ if (isOpen() && document.activeElement !== el) el.focus();
+ });
+ };
+ el.addEventListener('blur', onBlur);
+
+ onCleanup(() => {
+ cancelAnimationFrame(raf);
+ el.removeEventListener('blur', onBlur);
+ });
+ });
return (
<DropdownMenu.Sub gutter={4} open={isOpen()} onOpenChange={setIsOpen}>
@@ -369,24 +404,13 @@ const SearchableFilterSubmenu = (props: {
</DropdownMenu.SubTrigger>
<DropdownMenu.Portal>
- <DropdownMenu.SubContent
- class="z-action-menu bg-menu border border-edge-muted rounded-sm shadow-xl w-[260px] max-w-[90vw] overflow-hidden"
- onFocusIn={(e) => {
- // Kobalte focuses SubContent itself on open; redirect to the
- // search input so it gets focus deterministically.
- if (e.target === e.currentTarget && inputRef) {
- inputRef.focus();
- }
- }}
- >
+ <DropdownMenu.SubContent class="z-action-menu bg-menu border border-edge-muted rounded-sm shadow-xl w-[260px] max-w-[90vw] overflow-hidden">
<SearchableMultiSelectInline
options={props.options}
activeIds={props.activeIds}
onChange={props.onChange}
placeholder={props.placeholder}
- inputRef={(el) => {
- inputRef = el;
- }}
+ inputRef={setInputRef}
onRequestClose={() => setIsOpen(false)}
/>
</DropdownMenu.SubContent>