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(filters): keep filter submenus open while the mouse heads into them (#7990)

gbirman388477b0b5f7
diff --git a/apps/web/src/components/view-shell/ListDropdowns.test.tsx b/apps/web/src/components/view-shell/ListDropdowns.test.tsx
index 292ca5feaa..5f55003567 100644
--- a/apps/web/src/components/view-shell/ListDropdowns.test.tsx
+++ b/apps/web/src/components/view-shell/ListDropdowns.test.tsx
@@ -267,8 +267,17 @@ it('shared checkbox filters support Shift+Enter and close after ordinary Enter',
expect(checked()).toBe(false);
});
-function mousePointer(element: HTMLElement, type: string) {
- const event = new MouseEvent(type, { bubbles: true, cancelable: true });
+function mousePointer(
+ element: HTMLElement,
+ type: string,
+ at: { clientX: number; clientY: number } = { clientX: 0, clientY: 0 }
+) {
+ const event = new MouseEvent(type, {
+ // Like the browser, enter/leave do not bubble to the menu or document.
+ bubbles: type !== 'pointerenter' && type !== 'pointerleave',
+ cancelable: true,
+ ...at,
+ });
Object.defineProperty(event, 'pointerType', { value: 'mouse' });
fireEvent(element, event);
}
@@ -281,36 +290,114 @@ function crossMenuPadding() {
trigger.closest<HTMLElement>('[role="menu"]')!.focus();
}
+/**
+ * Opens Assignee, lays its submenu out to the left of the menu (where the
+ * Tasks and Home menus open them at the window's right edge), and leaves the
+ * Assignee row heading left, toward that submenu.
+ */
+async function leaveTowardAssigneeSubmenu(searchable: boolean) {
+ setup(false, searchable);
+ await openSubmenu();
+ const submenuChild = searchable
+ ? await screen.findByPlaceholderText('Search assignees...')
+ : await screen.findByRole('menuitemcheckbox', { name: 'Alice' });
+ const submenu = submenuChild.closest<HTMLElement>('[role="menu"]')!;
+ // jsdom has no viewport, so the submenu flips to the left once positioned.
+ await waitFor(() =>
+ expect(
+ submenu
+ .closest<HTMLElement>('[data-popper-positioner]')!
+ .style.getPropertyValue('--kb-popper-content-transform-origin')
+ ).toMatch(/^right/)
+ );
+ if (searchable)
+ await waitFor(() => expect(document.activeElement).toBe(submenuChild));
+ vi.spyOn(submenu, 'getBoundingClientRect').mockReturnValue(
+ new DOMRect(0, 0, 100, 200)
+ );
+ const assignee = screen.getByRole('menuitem', { name: 'Assignee' });
+ const menu = assignee.closest<HTMLElement>('[role="menu"]')!;
+ mousePointer(menu, 'pointermove', { clientX: 200, clientY: 20 });
+ mousePointer(menu, 'pointermove', { clientX: 150, clientY: 20 });
+ mousePointer(assignee, 'pointerleave', { clientX: 150, clientY: 20 });
+ return { assignee, menu };
+}
+
it.each([false, true])(
- 'switches immediately to a hovered sibling instead of preserving the old submenu (searchable: %s)',
+ 'keeps the open submenu while the mouse crosses a sibling toward it, then switches once it rests there (searchable: %s)',
async (searchable) => {
- setup(false, searchable);
- await openSubmenu();
- if (searchable) {
- const input = await screen.findByPlaceholderText('Search assignees...');
- await waitFor(() => expect(document.activeElement).toBe(input));
- } else await screen.findByRole('menuitemcheckbox', { name: 'Alice' });
-
- crossMenuPadding();
+ const { assignee } = await leaveTowardAssigneeSubmenu(searchable);
const files = screen.getByRole('menuitem', { name: 'Files' });
- mousePointer(files, 'pointerenter');
- // Kobalte may suppress pointermove while inside the old submenu's grace
- // polygon. Entering Files must work even without a subsequent pointermove.
- expect(files.getAttribute('aria-expanded')).toBe('true');
- expect(
- screen
- .getByRole('menuitem', { name: 'Assignee' })
- .getAttribute('aria-expanded')
- ).toBe('false');
+ mousePointer(files, 'pointerenter', { clientX: 140, clientY: 30 });
+ mousePointer(files, 'pointermove', { clientX: 140, clientY: 30 });
+ await new Promise((resolve) => setTimeout(resolve, 150));
+ expect(assignee.getAttribute('aria-expanded')).toBe('true');
+ expect(files.getAttribute('aria-expanded')).toBe('false');
+
+ // Kobalte suppresses pointermove inside the old submenu's grace polygon,
+ // so a mouse that stops on Files must still switch to it.
+ await waitFor(() =>
+ expect(files.getAttribute('aria-expanded')).toBe('true')
+ );
+ expect(assignee.getAttribute('aria-expanded')).toBe('false');
expect(
await screen.findByRole('menuitemradio', { name: 'All files' })
).toBeTruthy();
- await new Promise((resolve) => setTimeout(resolve, 300));
- expect(files.getAttribute('aria-expanded')).toBe('true');
expect(screen.queryByPlaceholderText('Search assignees...')).toBeNull();
}
);
+it('switches to a sibling straight away when the mouse moves away from the open submenu', async () => {
+ const { assignee, menu } = await leaveTowardAssigneeSubmenu(false);
+ const files = screen.getByRole('menuitem', { name: 'Files' });
+ for (const clientX of [160, 170, 180])
+ mousePointer(menu, 'pointermove', { clientX, clientY: 30 });
+ mousePointer(files, 'pointerenter', { clientX: 190, clientY: 30 });
+ mousePointer(files, 'pointermove', { clientX: 190, clientY: 30 });
+ expect(assignee.getAttribute('aria-expanded')).toBe('false');
+ await waitFor(() => expect(files.getAttribute('aria-expanded')).toBe('true'));
+});
+
+it.each([false, true])(
+ 'keeps following a slow mouse into the open submenu after Kobalte’s grace expires (searchable: %s)',
+ async (searchable) => {
+ const { assignee, menu } = await leaveTowardAssigneeSubmenu(searchable);
+ // Kobalte drops its grace polygon 300 ms after the mouse leaves Assignee.
+ await new Promise((resolve) => setTimeout(resolve, 350));
+ const files = screen.getByRole('menuitem', { name: 'Files' });
+ mousePointer(menu, 'pointermove', { clientX: 145, clientY: 25 });
+ mousePointer(files, 'pointerenter', { clientX: 140, clientY: 30 });
+ mousePointer(files, 'pointermove', { clientX: 140, clientY: 30 });
+ await new Promise((resolve) => setTimeout(resolve, 150));
+ mousePointer(files, 'pointermove', { clientX: 125, clientY: 35 });
+ mousePointer(files, 'pointerleave', { clientX: 110, clientY: 40 });
+ mousePointer(menu, 'pointermove', { clientX: 110, clientY: 40 });
+ await new Promise((resolve) => setTimeout(resolve, 150));
+ expect(files.getAttribute('aria-expanded')).toBe('false');
+ expect(assignee.getAttribute('aria-expanded')).toBe('true');
+
+ const submenu = document.getElementById(
+ assignee.getAttribute('aria-controls')!
+ )!;
+ mousePointer(submenu, 'pointerenter', { clientX: 95, clientY: 45 });
+ mousePointer(submenu, 'pointermove', { clientX: 95, clientY: 45 });
+ await new Promise((resolve) => setTimeout(resolve, 400));
+ expect(assignee.getAttribute('aria-expanded')).toBe('true');
+ }
+);
+
+it('closes the open submenu once the mouse stops short of it', async () => {
+ const { assignee, menu } = await leaveTowardAssigneeSubmenu(false);
+ await new Promise((resolve) => setTimeout(resolve, 350));
+ mousePointer(menu, 'pointermove', { clientX: 145, clientY: 25 });
+ // Kobalte focuses the menu when the mouse leaves a row outside its grace.
+ menu.focus();
+ expect(assignee.getAttribute('aria-expanded')).toBe('true');
+ await waitFor(() =>
+ expect(assignee.getAttribute('aria-expanded')).toBe('false')
+ );
+});
+
it('keeps a submenu open while crossing padding, cancelling dismissal on entry', async () => {
setup();
await openSubmenu();
diff --git a/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx b/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx
index 4bd62d8f43..d3c884fd5c 100644
--- a/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx
+++ b/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx
@@ -17,27 +17,110 @@ import {
type SearchableOption,
} from './searchable-multi-select';
-/** Keep a submenu alive while the mouse crosses the parent menu's padding. */
+const mouseTrail: { x: number; y: number; time: number }[] = [];
+let mouseTrailUsers = 0;
+const recordMouse = (event: PointerEvent) => {
+ if (event.pointerType !== 'mouse') return;
+ mouseTrail.push({
+ x: event.clientX,
+ y: event.clientY,
+ time: performance.now(),
+ });
+ if (mouseTrail.length > 4) mouseTrail.shift();
+};
+function trackMouseTrail() {
+ if (mouseTrailUsers++ === 0)
+ window.addEventListener('pointermove', recordMouse, true);
+ onCleanup(() => {
+ if (--mouseTrailUsers > 0) return;
+ window.removeEventListener('pointermove', recordMouse, true);
+ mouseTrail.length = 0;
+ });
+}
+
+/**
+ * Whether the mouse's latest movement points into `content`, so a submenu
+ * stays open while the mouse crosses other rows on the way to it. Unlike
+ * Kobalte's grace polygon, this follows the mouse instead of expiring 300 ms
+ * after it leaves the trigger.
+ */
+function isMouseHeadingInto(content: Element) {
+ const from = mouseTrail[0];
+ const to = mouseTrail.at(-1);
+ if (!from || !to || performance.now() - to.time > 100) return false;
+ const rect = content.getBoundingClientRect();
+ const edge =
+ to.x <= rect.left ? rect.left : to.x >= rect.right ? rect.right : null;
+ if (edge === null) return false;
+ const slack = 16;
+ const top = { x: edge - from.x, y: rect.top - slack - from.y };
+ const bottom = { x: edge - from.x, y: rect.bottom + slack - from.y };
+ const move = { x: to.x - from.x, y: to.y - from.y };
+ const cross = (a: typeof move, b: typeof move) => a.x * b.y - a.y * b.x;
+ const side = Math.sign(cross(top, bottom));
+ return (
+ side !== 0 &&
+ Math.sign(cross(top, move)) === side &&
+ Math.sign(cross(move, bottom)) === side
+ );
+}
+
+/** The content of another open submenu in the same menu as `trigger`. */
+function openSiblingContent(trigger: HTMLElement) {
+ const sibling = [
+ ...(trigger
+ .closest('[role="menu"]')
+ ?.querySelectorAll('[aria-haspopup][aria-expanded="true"]') ?? []),
+ ].find((element) => element !== trigger);
+ const id = sibling?.getAttribute('aria-controls');
+ return id ? document.getElementById(id) : null;
+}
+
+/**
+ * Keep a submenu alive while the mouse crosses the parent menu's padding or
+ * other rows on its way into the submenu.
+ */
function createFilterSubmenuHover(
options: {
open?: Accessor<boolean>;
onOpenChange?: (open: boolean) => void;
} = {}
) {
+ trackMouseTrail();
const [internalOpen, setInternalOpen] = createSignal(false);
const open = () => options.open?.() ?? internalOpen();
+ let content: HTMLElement | undefined;
let leavingWithMouse = false;
+ let switchingTrigger = false;
+ const headingIntoContent = () =>
+ !!content?.isConnected && isMouseHeadingInto(content);
const commitOpen = (value: boolean) => {
setInternalOpen(value);
options.onOpenChange?.(value);
};
- const closeAfterGap = debounce(() => commitOpen(false), 250);
+ const closeAfterGap = debounce(
+ () => (headingIntoContent() ? closeAfterGap() : commitOpen(false)),
+ 250
+ );
+ // Kobalte ignores a sibling row while the mouse heads toward an open sub,
+ // but only re-checks on pointermove: a mouse resting on the row would leave
+ // the old sub stuck open, so switch once it has rested there.
+ const openAfterRest = debounce((trigger: HTMLElement) => {
+ if (open()) return;
+ trigger.focus({ preventScroll: true });
+ setOpen(true);
+ }, 300);
const cancelGrace = () => {
leavingWithMouse = false;
closeAfterGap.clear();
+ openAfterRest.clear();
};
const setOpen = (value: boolean) => {
- if (!value && leavingWithMouse) {
+ if (
+ !value &&
+ !switchingTrigger &&
+ (leavingWithMouse || headingIntoContent())
+ ) {
closeAfterGap();
return;
}
@@ -53,13 +136,17 @@ function createFilterSubmenuHover(
event: PointerEvent & { currentTarget: HTMLElement }
) => {
cancelGrace();
+ if (event.pointerType === 'mouse') openAfterRest(event.currentTarget);
+ },
+ onPointerMove: (event: PointerEvent & { currentTarget: HTMLElement }) => {
if (event.pointerType !== 'mouse') return;
- // Entering a sibling row is an explicit switch, even when Kobalte's
- // grace polygon still considers the pointer headed toward the old sub.
- event.currentTarget.focus({ preventScroll: true });
- if (!open()) setOpen(true);
+ const sibling = openSiblingContent(event.currentTarget);
+ // Kobalte skips its hover switch for a prevented pointermove.
+ if (sibling && isMouseHeadingInto(sibling)) event.preventDefault();
+ openAfterRest(event.currentTarget);
},
onPointerLeave: (event: PointerEvent) => {
+ openAfterRest.clear();
// Kobalte's remaining pointerleave handler can focus the parent menu
// and synchronously close this sub when outside its grace polygon.
// Delay only those closes; later keyboard/focus changes stay immediate.
@@ -72,14 +159,22 @@ function createFilterSubmenuHover(
onPointerDown: cancelGrace,
},
contentProps: {
+ ref: (element: HTMLElement) => {
+ content = element;
+ },
onPointerEnter: cancelGrace,
onFocusOutside: (event: Event) => {
// Padding gets a grace period; switching submenu triggers does not.
if (
event.target instanceof Element &&
event.target.closest('[role="menuitem"][aria-haspopup]')
- )
+ ) {
cancelGrace();
+ switchingTrigger = true;
+ queueMicrotask(() => {
+ switchingTrigger = false;
+ });
+ }
},
onKeyDown: cancelGrace,
onEscapeKeyDown: cancelGrace,
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 7f98af2075..cd2c2a668f 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -1186,9 +1186,10 @@ is restricted to your own files. Recent offers only file-scope filtering.
Hold Shift while selecting or deselecting Type options to keep the submenu open
and combine several file types without reopening it. Desktop filter submenus allow a
250 ms grace period when the mouse crosses the parent menu's padding; entering
-the submenu cancels the pending close. Hovering another category immediately
-switches to that category, including when the submenu opens to the left.
-Escape and outside clicks still dismiss immediately.
+the submenu cancels the pending close. While the mouse heads toward an open
+submenu, including one that opens to the left, the categories it crosses on the
+way do not take over. A category the mouse moves to directly, or rests on for
+300 ms, opens in its place. Escape and outside clicks still dismiss immediately.
`Sort files` offers modified, created, and viewed dates.
Recent uses the viewer's own interaction order and does not offer a sort override.
The New menu and drag/drop uploads target the selected folder. **New → Folder**