An open source design system that's fully customizable and agent ready
TypeScript
fix(DropdownMenuItem): a link row starts no browser drag, so a dragged mouse press acts on the row under the release (#7197)
Christopher Chedeau13feb393632d
diff --git a/.changeset/dropdown-menu-link-row-no-drag.md b/.changeset/dropdown-menu-link-row-no-drag.mdnew file mode 100644index 0000000000..f950447ccf--- /dev/null+++ b/.changeset/dropdown-menu-link-row-no-drag.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A mouse press on a `DropdownMenuItem` link row (`href`) that moves a few pixels no longer starts the browser's link drag. The drag cancelled the press, so the highlight stopped following the mouse and the row under the release never acted; a press dragged from one link row to another now acts on the second, as it already did for rows without an address. Link rows render `draggable="false"`.++@vjeuxdiff --git a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx b/packages/core/src/DropdownMenu/DropdownMenu.test.tsxindex fa8f353eeb..2300fbf96b 100644--- a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx+++ b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx@@ -3184,6 +3184,27 @@ describe('DropdownMenuItem href', () => {expect(row).not.toHaveAttribute('href');expect(row).toHaveAttribute('aria-disabled', 'true');});++ it('a link row is not draggable; a row without an address keeps the default', () => {+ // A link is draggable by default, and a mouse press that moves a few+ // pixels on one starts the browser's link drag, which cancels the press+ // model's pointer stream before the row under the release can act.+ render(+ <DropdownMenu button={{label: 'Places'}}>+ <DropdownMenuItem label="Inbox" href="/inbox" />+ <DropdownMenuItem label="Archive" onClick={() => {}} />+ </DropdownMenu>,+ );+ const inbox = screen.getByRole('menuitem', {name: 'Inbox', hidden: true});+ expect(inbox.tagName).toBe('A');+ expect(inbox).toHaveAttribute('draggable', 'false');+ expect(inbox.draggable).toBe(false);+ const archive = screen.getByRole('menuitem', {+ name: 'Archive',+ hidden: true,+ });+ expect(archive).not.toHaveAttribute('draggable');+ });});describe("DropdownMenu link rows — the browser's own clicks", () => {diff --git a/packages/core/src/DropdownMenu/DropdownMenuItem.tsx b/packages/core/src/DropdownMenu/DropdownMenuItem.tsxindex e4db9cb102..2ec172ef08 100644--- a/packages/core/src/DropdownMenu/DropdownMenuItem.tsx+++ b/packages/core/src/DropdownMenu/DropdownMenuItem.tsx@@ -289,6 +289,11 @@ export function DropdownMenuItem({href={href}target={target}rel={rel}+ // A menu row is never a draggable link. Under a mouse, the browser's+ // native link drag starts a few pixels into a press and cancels the+ // pointer stream (`pointercancel`), so the press model could not let+ // the row under the release act.+ draggable={href != null ? false : undefined}isDisabled={isDisabled}xstyle={[menuItemStyles.root,diff --git a/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.ts b/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.tsindex e769f0148f..edbe1e3f88 100644--- a/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.ts+++ b/packages/core/src/DropdownMenu/__tests__/MenuPress.a11y.chromium.spec.ts@@ -5,7 +5,8 @@* @input Built DropdownMenu and Selector stories and real Chromium mouse,* touch (CDP) and pen (CDP) input* @output Browser evidence for the menu press model: the row under the- * release acts once, the highlight follows the pointer, a release outside+ * release acts once (a link row included: no native link drag cancels a+ * mouse press), the highlight follows the pointer, a release outside* closes under a mouse and not under a finger, a touch pan in an* overflowing menu cancels the gesture, a pen behaves like a finger, and* Escape after a press-open returns focus to the trigger@@ -31,6 +32,7 @@ test.afterAll(async () => {});const MENU_STORY = 'core-dropdownmenu--default';+const LINK_STORY = 'core-dropdownmenu--link-rows';const OVERFLOW_STORY = 'core-dropdownmenu--with-sections';const SELECTOR_STORY = 'core-selector--default';@@ -192,6 +194,55 @@ test.describe('DropdownMenu press model (Chromium)', () => {await expect(menu).toBeHidden();});+ test('mouse: a press dragged from one link row to another acts on the second; no link drag starts', async ({+ page,+ }) => {+ // The story's Settings row logs this line from its onClick.+ const acted: string[] = [];+ page.on('console', message => {+ if (message.text() === 'leaving for settings') {+ acted.push(message.text());+ }+ });+ await mount(page, LINK_STORY);+ await page.evaluate(() => {+ const probe = window as unknown as {linkDrags: number};+ probe.linkDrags = 0;+ document.addEventListener('dragstart', () => {+ probe.linkDrags += 1;+ });+ // Keep the story in place: the test reads the row's act, not the+ // navigation that follows it.+ document.addEventListener('click', event => {+ if (+ event.target instanceof Element &&+ event.target.closest('a[href]') != null+ ) {+ event.preventDefault();+ }+ });+ });+ await page.getByRole('button', {name: 'Places'}).click();+ const menu = page.getByRole('menu');+ await expect(menu).toBeVisible();++ const profile = await center(page, 'menuitem', 'Profile');+ const settings = await center(page, 'menuitem', 'Settings');+ await page.mouse.move(profile.x, profile.y);+ await page.mouse.down();+ await page.mouse.move(settings.x, settings.y, {steps: 6});+ expect(await activeRowName(page)).toBe('Settings');+ await page.mouse.up();++ await expect.poll(() => acted).toEqual(['leaving for settings']);+ await expect(menu).toBeHidden();+ expect(+ await page.evaluate(+ () => (window as unknown as {linkDrags: number}).linkDrags,+ ),+ ).toBe(0);+ });+test('mouse: a release outside the menu acts on nothing and closes it', async ({page,}) => {