Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(DropdownMenu): a menu a held finger opens stays open when that finger lifts on the trigger (#7241)

Christopher Chedeauddb8aa12ce35
diff --git a/.changeset/dropdown-menu-held-finger-lift.md b/.changeset/dropdown-menu-held-finger-lift.md
new file mode 100644
index 0000000000..09e2688108
--- /dev/null
+++ b/.changeset/dropdown-menu-held-finger-lift.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A DropdownMenu that a finger held on its trigger opens (after the long-press delay) stays open when that finger lifts on the trigger. The browser's light dismiss read the lift, outside the menu, as a press outside and closed the menu at once; the trigger is now held as the menu's invoker through the press, as it already was for a mouse press.
+
+@vjeux
diff --git a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
index 82580af4d5..f0249b36ff 100644
--- a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
@@ -2664,6 +2664,30 @@ describe('DropdownMenu press model', () => {
}
});
+ it('a menu a held finger opens keeps its trigger as the invoker until the finger lifts', () => {
+ // A release on the trigger is outside the `popover="auto"` menu, so the
+ // browser's light dismiss would close it; holding the invoker through
+ // the press exempts the trigger, as it does for a mouse press.
+ vi.useFakeTimers();
+ try {
+ const trigger = renderMenu();
+ fireEvent.pointerDown(trigger, touch);
+ act(() => {
+ vi.advanceTimersByTime(500);
+ });
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
+ expect(trigger).toHaveAttribute('popovertarget');
+ fireEvent.pointerUp(trigger, touch);
+ act(() => {
+ vi.advanceTimersByTime(0);
+ });
+ expect(trigger).not.toHaveAttribute('popovertarget');
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it('a tap on the trigger still opens through its click', () => {
const trigger = renderMenu();
fireEvent.pointerDown(trigger, touch);
diff --git a/packages/core/src/DropdownMenu/DropdownMenu.tsx b/packages/core/src/DropdownMenu/DropdownMenu.tsx
index 9fe1d2486e..0e5596afb9 100644
--- a/packages/core/src/DropdownMenu/DropdownMenu.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenu.tsx
@@ -1009,12 +1009,14 @@ function DropdownMenuPopover({
// Escape or a pick returns focus (the APG menu-button pattern).
buttonRef.current?.focus({preventScroll: true});
const didOpen = openAndFocus('pointer', true);
- if (didOpen && pointerType === 'mouse') {
+ if (didOpen) {
// The menu is `popover="auto"`: the browser's light dismiss would
// read the release of this very press, on the trigger outside the
- // popover, as a dismissal. Holding the invoker relationship through
- // the press exempts the trigger, the way useKeepLayerOpenProps does
- // for controls beside an open layer.
+ // popover, as a dismissal — a mouse's release, and as much a
+ // finger's after the long-press delay opened the menu under it.
+ // Holding the invoker relationship through the press exempts the
+ // trigger, the way useKeepLayerOpenProps does for controls beside
+ // an open layer.
holdInvokerThroughPress(buttonRef.current, popover.id);
}
return didOpen;
diff --git a/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.ts b/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.ts
index 36801f3e83..e769f0148f 100644
--- a/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.ts
+++ b/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.ts
@@ -294,6 +294,22 @@ test.describe('DropdownMenu press model (Chromium)', () => {
expect(activations).toEqual([]);
});
+ test('touch: a menu a held finger opens stays open when that finger lifts on the trigger', async ({
+ page,
+ }) => {
+ const activations = collectActivations(page);
+ const cdp = await enableTouch(page);
+ await mount(page, MENU_STORY);
+ await touch.start(cdp, await center(page, TRIGGER));
+ const menu = page.getByRole('menu');
+ // The long-press delay opens the menu with the finger still down.
+ await expect(menu).toBeVisible();
+ await touch.end(cdp);
+ await page.waitForTimeout(400);
+ await expect(menu).toBeVisible();
+ expect(activations).toEqual([]);
+ });
+
test('touch: a vertical pan in an overflowing menu scrolls it and acts on nothing', async ({
page,
}) => {