An open source design system that's fully customizable and agent ready
TypeScript
fix(TopNav): a mouse slide across TopNavMenu's action items selects no text (#8807)
Cindy Zhang7824f29dcff4
diff --git a/.changeset/topnavmenu-action-rows-no-selection.md b/.changeset/topnavmenu-action-rows-no-selection.mdnew file mode 100644index 0000000000..9ad44bec4c--- /dev/null+++ b/.changeset/topnavmenu-action-rows-no-selection.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A mouse slide across TopNavMenu's action items (items with an `onClick` and no `href`) no longer selects their text.++@cixzhangdiff --git a/apps/storybook/stories/TopNavMenu.stories.tsx b/apps/storybook/stories/TopNavMenu.stories.tsxindex 437a118c99..a974a4b67d 100644--- a/apps/storybook/stories/TopNavMenu.stories.tsx+++ b/apps/storybook/stories/TopNavMenu.stories.tsx@@ -101,6 +101,37 @@ export const Default: Story = {),};+/**+ * A nav menu of action items (no destinations): each runs its `onClick`.+ */+export const ActionItems: Story = {+ render: () => (+ <TopNav+ label="Main navigation"+ heading={<TopNavHeading heading="My App" headingHref="#" />}+ startContent={+ <TopNavMenu+ label="Actions"+ items={[+ {+ title: 'Invite teammates',+ description: 'Send an invite by email',+ icon: <UserCircleIcon style={{width: 20, height: 20}} />,+ onClick: () => {},+ },+ {+ title: 'Run automation',+ description: 'Start the default workflow',+ icon: <BoltIcon style={{width: 20, height: 20}} />,+ onClick: () => {},+ },+ ]}+ />+ }+ />+ ),+};+/*** Multiple nav menus side by side. Hovering one closes the other* (standard hover-menu behavior).diff --git a/packages/core/src/NavMenu/__tests__/NavMenusSlideSelection.a11y.chromium.spec.ts b/packages/core/src/NavMenu/__tests__/NavMenusSlideSelection.a11y.chromium.spec.tsindex bb7df34f0f..f4c28862d1 100644--- a/packages/core/src/NavMenu/__tests__/NavMenusSlideSelection.a11y.chromium.spec.ts+++ b/packages/core/src/NavMenu/__tests__/NavMenusSlideSelection.a11y.chromium.spec.ts@@ -50,9 +50,13 @@ async function selectedText(page: Page): Promise<string> {* 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) {+async function slideFirstToSecond(page: Page, item: string, text?: string) {await expect(page.locator(item).nth(1)).toBeVisible();- const first = await page.locator(item).nth(0).boundingBox();+ const first = await (+ text == null+ ? page.locator(item).nth(0)+ : page.locator(item).nth(0).getByText(text, {exact: true})+ ).boundingBox();const to = await centerOf(page, item, 1);if (first == null) {throw new Error(`${item} #0 has no rendered bounds`);@@ -108,6 +112,18 @@ test.describe('nav and tab menus: a mouse slide selects no text (Chromium)', ()});});+ test('TopNavMenu, on action items with no destination', async ({page}) => {+ await mount(page, 'core-topnavmenu--action-items');+ await page+ .locator('#storybook-root button', {hasText: 'Actions'})+ .first()+ .click();+ // Start on the title text, past the icon cell.+ expect(+ await slideFirstToSecond(page, MENU_ITEMS, 'Invite teammates'),+ ).toEqual({held: '', lifted: ''});+ });+test('TabMenu', async ({page}) => {await mount(page, 'core-tablist--with-menu');await pagediff --git a/packages/core/src/TopNav/TopNavMenu.tsx b/packages/core/src/TopNav/TopNavMenu.tsxindex c1208427be..ddb0be08dd 100644--- a/packages/core/src/TopNav/TopNavMenu.tsx+++ b/packages/core/src/TopNav/TopNavMenu.tsx@@ -113,6 +113,8 @@ const styles = stylex.create({transform: 'rotate(180deg)',},menuContainer: {+ // A held pointer slides across the items; it selects no text.+ userSelect: 'none',display: 'flex',flexDirection: 'column',gap: spacingVars['--spacing-1'],