An open source design system that's fully customizable and agent ready
TypeScript
fix(core): a mouse slide across NavHeadingMenu or TabMenu items selects no text (#8802)
Cindy Zhang21436d9d8d7d
diff --git a/.changeset/nav-menus-no-text-selection.md b/.changeset/nav-menus-no-text-selection.mdnew file mode 100644index 0000000000..371641f02a--- /dev/null+++ b/.changeset/nav-menus-no-text-selection.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A mouse slide across the items of NavHeadingMenu or TabMenu no longer selects their text. In an expanded SideNavHeading, which stays open after a pick, the selection used to stay on the item the press began on. Caller content beside NavHeadingMenu's items stays selectable.++@cixzhangdiff --git a/packages/core/src/NavMenu/NavHeadingMenuItem.tsx b/packages/core/src/NavMenu/NavHeadingMenuItem.tsxindex c7680505e5..cc1f2c4e01 100644--- a/packages/core/src/NavMenu/NavHeadingMenuItem.tsx+++ b/packages/core/src/NavMenu/NavHeadingMenuItem.tsx@@ -32,6 +32,9 @@ import {themeProps} from '../utils/themeProps';const styles = stylex.create({root: {boxSizing: 'border-box',+ // A held pointer slides across the items; it selects no item text.+ // Caller content beside the items stays selectable.+ userSelect: 'none',display: 'flex',alignItems: 'center',gap: spacingVars['--spacing-2'],diff --git a/packages/core/src/NavMenu/__tests__/NavMenusSlideSelection.a11y.chromium.spec.ts b/packages/core/src/NavMenu/__tests__/NavMenusSlideSelection.a11y.chromium.spec.tsnew file mode 100644index 0000000000..bb7df34f0f--- /dev/null+++ b/packages/core/src/NavMenu/__tests__/NavMenusSlideSelection.a11y.chromium.spec.ts@@ -0,0 +1,121 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @pr-a11y release-only++/**+ * @file NavMenusSlideSelection.a11y.chromium.spec.ts+ * @input The built TopNav With Heading Menu (NavHeadingMenu), TopNavMenu+ * Default and TabList With Menu stories, in Chromium, with a real mouse+ * @output Proof that a mouse slide from one item to the next selects no+ * text in NavHeadingMenu (in TopNavHeading's and an expanded SideNavHeading's+ * menus), TopNavMenu and TabMenu, while held and after the lift+ * @position Evidence for the action-group slide in /packages/core/src/NavMenu,+ * TopNav and TabList (`family:action-groups` FR1-FR2)+ */++import {expect, test, type Page} from '@playwright/test';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;+test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});+test.afterAll(async () => {+ await storybook?.close();+});++async function mount(page: Page, story: string) {+ await page.goto(`${storybook.origin}/iframe.html?id=${story}&viewMode=story`);+ await expect(page.locator('#storybook-root')).toBeVisible();+}++async function centerOf(page: Page, selector: string, index: number) {+ const box = await page.locator(selector).nth(index).boundingBox();+ if (box == null) {+ throw new Error(`${selector} #${index} has no rendered bounds`);+ }+ return {x: box.x + box.width / 2, y: box.y + box.height / 2};+}++async function selectedText(page: Page): Promise<string> {+ return page.evaluate(() => window.getSelection()?.toString() ?? '');+}++/**+ * Press the first item's text, slide to the second, and lift there. Returns+ * the selected text while the pointer is held and after the lift.+ */+async function slideFirstToSecond(page: Page, item: string) {+ await expect(page.locator(item).nth(1)).toBeVisible();+ const first = await page.locator(item).nth(0).boundingBox();+ const to = await centerOf(page, item, 1);+ if (first == null) {+ throw new Error(`${item} #0 has no rendered bounds`);+ }+ // Start on the label's text, where a browser selection begins.+ await page.mouse.move(first.x + 12, first.y + first.height / 2);+ await page.mouse.down();+ await page.mouse.move(to.x, to.y, {steps: 8});+ const held = await selectedText(page);+ await page.mouse.up();+ return {held, lifted: await selectedText(page)};+}++const MENU_ITEMS = '[role="menu"] [role="menuitem"]';++test.describe('nav and tab menus: a mouse slide selects no text (Chromium)', () => {+ test('NavHeadingMenu, in TopNavHeading’s product menu', async ({page}) => {+ await mount(page, 'core-topnav--with-heading-menu');+ // The trigger overlays the heading; a click at its center opens the menu.+ await page+ .locator('#storybook-root button[aria-haspopup]')+ .first()+ .click({force: true});+ expect(await slideFirstToSecond(page, MENU_ITEMS)).toEqual({+ held: '',+ lifted: '',+ });+ });++ test('NavHeadingMenu, in an expanded SideNavHeading’s menu', async ({+ page,+ }) => {+ await mount(page, 'core-sidenav--with-header-menu-items');+ await page+ .locator('#storybook-root button[aria-haspopup]')+ .first()+ .click({force: true});+ expect(await slideFirstToSecond(page, MENU_ITEMS)).toEqual({+ held: '',+ lifted: '',+ });+ });++ test('TopNavMenu', async ({page}) => {+ await mount(page, 'core-topnavmenu--default');+ await page+ .locator('#storybook-root button', {hasText: 'Products'})+ .first()+ .click();+ expect(await slideFirstToSecond(page, MENU_ITEMS)).toEqual({+ held: '',+ lifted: '',+ });+ });++ test('TabMenu', async ({page}) => {+ await mount(page, 'core-tablist--with-menu');+ await page+ .locator('#storybook-root button[aria-haspopup]', {hasText: 'More'})+ .first()+ .click();+ expect(+ await slideFirstToSecond(page, '[role="menu"] [role="menuitemradio"]'),+ ).toEqual({held: '', lifted: ''});+ });+});diff --git a/packages/core/src/TabList/TabMenu.tsx b/packages/core/src/TabList/TabMenu.tsxindex 53cbbc6e77..5a8cdee14a 100644--- a/packages/core/src/TabList/TabMenu.tsx+++ b/packages/core/src/TabList/TabMenu.tsx@@ -175,6 +175,8 @@ const styles = stylex.create({transform: 'rotate(180deg)',},dropdown: {+ // A held pointer slides across the items; it selects no text.+ userSelect: 'none',display: 'flex',flexDirection: 'column',gap: spacingVars['--spacing-0-5'],