An open source design system that's fully customizable and agent ready
TypeScript
feat(DropdownMenu): DropdownMenuGroup, a titled group of rows for compound-mode menus (#6684)
Christopher Chedeau52a359239527
diff --git a/.changeset/dropdown-menu-group.md b/.changeset/dropdown-menu-group.mdnew file mode 100644index 0000000000..664c610ef2--- /dev/null+++ b/.changeset/dropdown-menu-group.md@@ -0,0 +1,15 @@+---+'@astryxdesign/core': patch+---++[feat] Add `DropdownMenuGroup`, a titled `role="group"` of rows for compound-mode menus.++The `items` data API could title a group (`{type: 'section', title, items}`);+a menu written with children — checkbox rows, radio groups, rows mounted only+while open — could not. `DropdownMenuGroup` (also `ContextMenuGroup` and+`BreadcrumbMenuGroup`) renders a `role="group"` named by its heading through+`aria-labelledby`; the heading shares the data mode's typography and+`astryx-dropdown-menu-section-heading` theme target, is not a menu item, and is+skipped by arrow keys and typeahead. Existing menus are unchanged.++@vjeuxdiff --git a/apps/sandbox/scripts/next-export-routes.json b/apps/sandbox/scripts/next-export-routes.jsonindex 6476b0dcb2..b093a2bcc9 100644--- a/apps/sandbox/scripts/next-export-routes.json+++ b/apps/sandbox/scripts/next-export-routes.json@@ -292,6 +292,8 @@"/templates/DividerVertical/","/templates/DropdownMenuActions/","/templates/DropdownMenuBottomSheet/",+ "/templates/DropdownMenuGroupShowcase/",+ "/templates/DropdownMenuGroupWithSelectable/","/templates/DropdownMenuItemBasic/","/templates/DropdownMenuItemShowcase/","/templates/DropdownMenuNoChevron/",diff --git a/apps/storybook/stories/DropdownMenu.stories.tsx b/apps/storybook/stories/DropdownMenu.stories.tsxindex b78206c369..20049f0b94 100644--- a/apps/storybook/stories/DropdownMenu.stories.tsx+++ b/apps/storybook/stories/DropdownMenu.stories.tsx@@ -9,6 +9,7 @@ import {DropdownMenu,DropdownMenuItem,DropdownMenuDivider,+ DropdownMenuGroup,DropdownMenuCheckboxItem,DropdownMenuRadioGroup,DropdownMenuRadioItem,@@ -676,6 +677,38 @@ export const CompoundWithDescriptions: Story = {),};+export const CompoundWithGroups: Story = {+ render: () => (+ <DropdownMenu button={{label: 'Version'}}>+ <DropdownMenuGroup title="Version history">+ <DropdownMenuItem+ icon={ArrowDownTrayIcon}+ label="Restore this version"+ onClick={() => console.log('Restore')}+ />+ <DropdownMenuItem+ icon={DocumentDuplicateIcon}+ label="Compare with current"+ onClick={() => console.log('Compare')}+ />+ </DropdownMenuGroup>+ <DropdownMenuDivider />+ <DropdownMenuGroup title="Add to message">+ <DropdownMenuItem+ icon={ShareIcon}+ label="As a link"+ onClick={() => console.log('Link')}+ />+ <DropdownMenuItem+ icon={DocumentPlusIcon}+ label="As a snippet"+ onClick={() => console.log('Snippet')}+ />+ </DropdownMenuGroup>+ </DropdownMenu>+ ),+};+export const PlacementAbove: Story = {render: () => (<DropdownMenudiff --git a/internal/shadcn-registry/routes.lock.json b/internal/shadcn-registry/routes.lock.jsonindex 2b74460732..cbb3e00418 100644--- a/internal/shadcn-registry/routes.lock.json+++ b/internal/shadcn-registry/routes.lock.json@@ -361,6 +361,11 @@"path": "components/dropdown-menu-divider","aliases": []},+ {+ "name": "component-dropdown-menu-group",+ "path": "components/dropdown-menu-group",+ "aliases": []+ },{"name": "component-dropdown-menu-item","path": "components/dropdown-menu-item",@@ -2010,6 +2015,11 @@"path": "examples/drawer/width-budget-pixels-or-any-css-length","aliases": []},+ {+ "name": "example-dropdown-menu-group-selectable-rows",+ "path": "examples/dropdown-menu-group/selectable-rows",+ "aliases": []+ },{"name": "example-dropdown-menu-item-basic","path": "examples/dropdown-menu-item/basic",@@ -4240,6 +4250,11 @@"path": "showcases/drawer/basic","aliases": []},+ {+ "name": "showcase-dropdown-menu-group-default",+ "path": "showcases/dropdown-menu-group/default",+ "aliases": []+ },{"name": "showcase-dropdown-menu-item-default","path": "showcases/dropdown-menu-item/default",diff --git a/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjsnew file mode 100644index 0000000000..8d966d17ef--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs@@ -0,0 +1,15 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */+export const doc = {+ type: 'block',+ exampleFor: 'DropdownMenuGroup',+ name: 'DropdownMenuGroup',+ displayName: 'Dropdown Menu Group',+ description:+ 'A compound-mode menu whose rows are titled in groups. Each DropdownMenuGroup renders a role="group" named by its heading; arrow keys and typeahead skip the heading.',+ isReady: true,+ isShowcase: true,+ aspectRatio: 16 / 9,+ componentsUsed: ['DropdownMenu', 'DropdownMenuGroup', 'DropdownMenuItem'],+};diff --git a/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsxnew file mode 100644index 0000000000..9f81c647b3--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx@@ -0,0 +1,38 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++'use client';++import {+ DropdownMenu,+ DropdownMenuDivider,+ DropdownMenuGroup,+ DropdownMenuItem,+} from '@astryxdesign/core/DropdownMenu';++export default function DropdownMenuGroupShowcase() {+ return (+ <DropdownMenu button={{label: 'Version'}}>+ <DropdownMenuGroup title="Version history">+ <DropdownMenuItem+ icon="arrowDown"+ label="Restore this version"+ onClick={() => {}}+ />+ <DropdownMenuItem+ icon="copy"+ label="Compare with current"+ onClick={() => {}}+ />+ </DropdownMenuGroup>+ <DropdownMenuDivider />+ <DropdownMenuGroup title="Add to message">+ <DropdownMenuItem+ icon="externalLink"+ label="As a link"+ onClick={() => {}}+ />+ <DropdownMenuItem label="As a snippet" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>+ );+}diff --git a/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjsnew file mode 100644index 0000000000..ed8e9ff06a--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs@@ -0,0 +1,20 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */+export const doc = {+ type: 'block',+ exampleFor: 'DropdownMenuGroup',+ name: 'DropdownMenuGroup — Selectable rows',+ displayName: 'DropdownMenuGroup — Selectable rows',+ description:+ 'Titled groups around a radio group and checkbox rows — the rows the data API cannot express, which is why the heading lives in compound mode.',+ isReady: true,+ aspectRatio: 16 / 9,+ componentsUsed: [+ 'DropdownMenu',+ 'DropdownMenuGroup',+ 'DropdownMenuRadioGroup',+ 'DropdownMenuRadioItem',+ 'DropdownMenuCheckboxItem',+ ],+};diff --git a/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsxnew file mode 100644index 0000000000..12d35ca5e4--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx@@ -0,0 +1,48 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++'use client';++import {useState} from 'react';+import {+ DropdownMenu,+ DropdownMenuCheckboxItem,+ DropdownMenuDivider,+ DropdownMenuGroup,+ DropdownMenuRadioGroup,+ DropdownMenuRadioItem,+} from '@astryxdesign/core/DropdownMenu';++export default function DropdownMenuGroupWithSelectable() {+ const [model, setModel] = useState('balanced');+ const [notify, setNotify] = useState(true);+ const [retry, setRetry] = useState(false);++ return (+ <DropdownMenu button={{label: 'Run settings'}}>+ <DropdownMenuGroup title="Model">+ <DropdownMenuRadioGroup+ label="Model"+ value={model}+ onChange={setModel}+ hasCloseOnSelect={false}>+ <DropdownMenuRadioItem value="fast" label="Fast" />+ <DropdownMenuRadioItem value="balanced" label="Balanced" />+ <DropdownMenuRadioItem value="thorough" label="Thorough" />+ </DropdownMenuRadioGroup>+ </DropdownMenuGroup>+ <DropdownMenuDivider />+ <DropdownMenuGroup title="On completion">+ <DropdownMenuCheckboxItem+ label="Notify me"+ value={notify}+ onChange={setNotify}+ />+ <DropdownMenuCheckboxItem+ label="Retry on failure"+ value={retry}+ onChange={setRetry}+ />+ </DropdownMenuGroup>+ </DropdownMenu>+ );+}diff --git a/packages/cli/test/doc-routes.ids.json b/packages/cli/test/doc-routes.ids.jsonindex 6d922c99e1..f53ae51db1 100644--- a/packages/cli/test/doc-routes.ids.json+++ b/packages/cli/test/doc-routes.ids.json@@ -65,6 +65,7 @@"DropdownMenu","DropdownMenuCheckboxItem","DropdownMenuDivider",+ "DropdownMenuGroup","DropdownMenuItem","DropdownMenuRadioGroup","DropdownMenuRadioItem",@@ -540,6 +541,8 @@"DividerVertical","DropdownMenuActions","DropdownMenuBottomSheet",+ "DropdownMenuGroupShowcase",+ "DropdownMenuGroupWithSelectable","DropdownMenuItemBasic","DropdownMenuItemShowcase","DropdownMenuNoChevron",diff --git a/packages/cli/test/doc-routes.json b/packages/cli/test/doc-routes.jsonindex f2c63f4441..74ba25d8ec 100644--- a/packages/cli/test/doc-routes.json+++ b/packages/cli/test/doc-routes.json@@ -4348,7 +4348,7 @@"kind": "component","id": "@astryxdesign/core/component","provider": "@astryxdesign/core",- "count": 176,+ "count": 177,"oldCliRoute": "astryx component <id>","oldDocsiteUrl": "/components/<id>","docsiteExceptions": {@@ -4415,7 +4415,7 @@"kind": "block","id": "@astryxdesign/core/block","provider": "@astryxdesign/core",- "count": 659,+ "count": 661,"oldCliRoute": "astryx template <id> --type block","oldDocsiteUrl": null,"placement": "generated:@astryxdesign/core/block",diff --git a/packages/core/src/Breadcrumbs/Breadcrumbs.test.tsx b/packages/core/src/Breadcrumbs/Breadcrumbs.test.tsxindex c4f56180d6..8529794c1c 100644--- a/packages/core/src/Breadcrumbs/Breadcrumbs.test.tsx+++ b/packages/core/src/Breadcrumbs/Breadcrumbs.test.tsx@@ -7,6 +7,7 @@ import {Breadcrumbs} from './Breadcrumbs';import {BreadcrumbItem} from './BreadcrumbItem';import {BreadcrumbMenuItem,+ BreadcrumbMenuGroup,BreadcrumbMenuCheckboxItem,BreadcrumbMenuRadioGroup,BreadcrumbMenuRadioItem,@@ -769,4 +770,33 @@ describe('BreadcrumbItem menu', () => {);expect(separators).toHaveLength(3);});++ it('carries the group semantics through the BreadcrumbMenuGroup alias', async () => {+ // The alias must bring the semantics, not just the component: a group+ // that renders but is not named leaves a screen reader with a run of+ // loose rows where a sighted user sees a cluster.+ const user = userEvent.setup();+ render(+ <Breadcrumbs>+ <BreadcrumbItem+ menu={+ <BreadcrumbMenuGroup title="Recent">+ <BreadcrumbMenuItem label="Overview" onClick={() => {}} />+ <BreadcrumbMenuItem label="Settings" onClick={() => {}} />+ </BreadcrumbMenuGroup>+ }>+ Project+ </BreadcrumbItem>+ <BreadcrumbItem isCurrent>Current</BreadcrumbItem>+ </Breadcrumbs>,+ );+ await user.click(screen.getByRole('button', {name: 'Project'}));++ const group = screen.getByRole('group', {name: 'Recent', hidden: true});+ const heading = screen.getByText('Recent');+ expect(group).toHaveAttribute('aria-labelledby', heading.id);+ expect(group).toContainElement(+ screen.getByRole('menuitem', {name: 'Overview', hidden: true}),+ );+ });});diff --git a/packages/core/src/Breadcrumbs/index.ts b/packages/core/src/Breadcrumbs/index.tsindex 72c7a51b9c..9630b4be4f 100644--- a/packages/core/src/Breadcrumbs/index.ts+++ b/packages/core/src/Breadcrumbs/index.ts@@ -41,6 +41,10 @@ export {DropdownMenuDivider as BreadcrumbMenuDivider,type DropdownMenuDividerProps as BreadcrumbMenuDividerProps,} from '../DropdownMenu/DropdownMenuDivider';+export {+ DropdownMenuGroup as BreadcrumbMenuGroup,+ type DropdownMenuGroupProps as BreadcrumbMenuGroupProps,+} from '../DropdownMenu/DropdownMenuGroup';export {DropdownMenuCheckboxItem as BreadcrumbMenuCheckboxItem,type DropdownMenuCheckboxItemProps as BreadcrumbMenuCheckboxItemProps,diff --git a/packages/core/src/ContextMenu/ContextMenu.test.tsx b/packages/core/src/ContextMenu/ContextMenu.test.tsxindex 7ed8d34967..c880a9cc3b 100644--- a/packages/core/src/ContextMenu/ContextMenu.test.tsx+++ b/packages/core/src/ContextMenu/ContextMenu.test.tsx@@ -13,6 +13,7 @@ import {render, screen, fireEvent, act, waitFor} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {readFileSync} from 'node:fs';import {ContextMenu} from './ContextMenu';+import {ContextMenuGroup} from './index';import {ContextMenuItem,ContextMenuDivider,@@ -1064,6 +1065,43 @@ describe('ContextMenu press model', () => {});});+describe('ContextMenuGroup', () => {+ it('carries the group semantics through the alias, not just the component', async () => {+ // Three public surfaces alias this component at once. An alias that+ // re-exports without the semantics would pass a render test and fail a+ // screen reader.+ const user = userEvent.setup();+ render(+ <ContextMenu+ menuContent={+ <ContextMenuGroup title="Version history">+ <DropdownMenuItem label="Restore" onClick={() => {}} />+ <DropdownMenuItem label="Compare" onClick={() => {}} />+ </ContextMenuGroup>+ }>+ <div data-testid="target">Right-click me</div>+ </ContextMenu>,+ );++ fireEvent.contextMenu(screen.getByTestId('target'));+ await waitFor(() =>+ expect(+ screen.getByRole('menuitem', {name: 'Restore', hidden: true}),+ ).toBeInTheDocument(),+ );++ const group = screen.getByRole('group', {+ name: 'Version history',+ hidden: true,+ });+ const heading = screen.getByText('Version history');+ expect(group).toHaveAttribute('aria-labelledby', heading.id);+ expect(group).toContainElement(+ screen.getByRole('menuitem', {name: 'Restore', hidden: true}),+ );+ });+});+describe('ContextMenu keyboard', () => {const item = (name: string) =>screen.getByRole('menuitem', {name, hidden: true});diff --git a/packages/core/src/ContextMenu/index.ts b/packages/core/src/ContextMenu/index.tsindex cb3cfb3629..f0f5bc73ff 100644--- a/packages/core/src/ContextMenu/index.ts+++ b/packages/core/src/ContextMenu/index.ts@@ -25,6 +25,10 @@ export {DropdownMenuDivider as ContextMenuDivider,type DropdownMenuDividerProps as ContextMenuDividerProps,} from '../DropdownMenu/DropdownMenuDivider';+export {+ DropdownMenuGroup as ContextMenuGroup,+ type DropdownMenuGroupProps as ContextMenuGroupProps,+} from '../DropdownMenu/DropdownMenuGroup';// Selectable items work inside a ContextMenu too — re-exported under the// ContextMenu name for a coherent API.diff --git a/packages/core/src/DropdownMenu/DropdownMenu.doc.mjs b/packages/core/src/DropdownMenu/DropdownMenu.doc.mjsindex 9dea8ed1be..b4de7ee905 100644--- a/packages/core/src/DropdownMenu/DropdownMenu.doc.mjs+++ b/packages/core/src/DropdownMenu/DropdownMenu.doc.mjs@@ -53,7 +53,7 @@ const anatomy = [name: 'Pointer section heading',required: false,description:- 'Heading that labels a data-driven section in an anchored menu.',+ 'Heading that labels a group of rows in an anchored menu: a data-driven section or a compound DropdownMenuGroup.',},{name: 'Pointer divider',diff --git a/packages/core/src/DropdownMenu/DropdownMenu.spec.md b/packages/core/src/DropdownMenu/DropdownMenu.spec.mdindex 1484bdce85..69fd62a182 100644--- a/packages/core/src/DropdownMenu/DropdownMenu.spec.md+++ b/packages/core/src/DropdownMenu/DropdownMenu.spec.md@@ -112,6 +112,7 @@ released default.| FR11 | When a compact touch display opened the pointer menu (`COMPACT_TOUCH_PRESENTATION_QUERY`, the same query the root presentation uses for its bottom sheet, sampled once as it opens) an `adaptive` sub-menu row MUST drill in: its rows and a leading Back row named "Back to <parent>" replace the menu's rows in the same Pointer menu surface, no flyout opens, the drilled list is a `menu` named by the row's label, and Back, Escape and ArrowLeft MUST return to the row with focus on it; a pick inside closes the whole menu. Roving focus and typeahead scope to the shown rows; sibling rows and dividers need no knowledge of it. `presentation="flyout"` keeps the flyout; `"drill-in"` drills in on any pointer. | `component:DropdownMenu/DEC-2`; `architecture:interaction-modality` | Proposed; verified in jsdom and Chromium (coarse pointer); owner to confirm DEC-5 || FR12 | In the pointer menu ArrowDown on the last enabled row wraps to the first and ArrowUp on the first to the last; PageDown and PageUp move to the last and first fully visible enabled row and, pressed there again, one viewport further without wrapping; ArrowUp on the trigger opens with the last enabled row highlighted; the key that opened the menu and its auto-repeats do not activate; typeahead matches the row's label element alone and ignores Control/Command chords and input-method composition. | Proposed in this change; `DropdownMenu.test.tsx` keyboard suite, `useListFocus.test.tsx`, `useTypeahead.test.tsx` | Proposed; verified in jsdom, pending owner review || FR13 | On a mouse, a nested flyout stays open while the pointer is inside the triangle from where it left its row to the flyout's near edge — including while the pointer is paused there — and closes after the existing delay once the pointer has left both the row and that triangle. The row's click toggle and its guard window are unchanged. | Proposed in this change; `DropdownMenuSubMenu.test.tsx` safe-triangle suite, `useMenuHover.test.tsx` | Proposed; verified in jsdom, pending owner review |+| FR14 | A compound `DropdownMenuGroup` is one `role="group"` named by its heading through `aria-labelledby`; the heading carries `dropdown-menu-section-heading`, is plain text rather than a menu item, and is skipped by roving focus and typeahead. An untitled group is an unnamed `role="group"`. | DEC-1, docs, and tests | Proposed; awaiting owner approval |### Allowed variation@@ -279,10 +280,9 @@ than adding a DropdownMenu-owned heading target.### DEC-1 — Pointer dismissal returns focus to the trigger, ring suppressed-### DEC-2 — Arrow keys wrap in a menu-**Reference:** `component:DropdownMenu/DEC-1`-**Decider:** pending owner review++**Decider:** `cixzhang`, 2026-10-02The shipped behavior blurred the trigger after a pointer dismissal so Safariwould not paint a ring after a touch pick. Focus falling to the page loses a@@ -294,25 +294,6 @@ in `module:DropdownMenu/useMenuPress`.### DEC-2 — `menuMaxHeight` is a number of pixels-### DEC-3 — A safe triangle protects the diagonal to a flyout--**Reference:** `component:DropdownMenu/DEC-2`-**Decider:** `cixzhang`, `2026-10-02`--`menuMaxHeight` replaces only the 300px term of the cap; the viewport gutters-still bound the menu, so a menu that must show all of its rows (a docked phone-menu of eleven 44px rows) can, without ever overflowing the screen. The dynamic-value uses `100dvb` alone; every browser with anchor positioning has it.--A prop rather than a theme variable, because the need is situational — one-menu with many rows — rather than a product-wide preference, and a prop reads-more clearly at the callsite that has the problem.--The value is a number of pixels. Rejected: an arbitrary CSS length (`50vh`,-`calc(...)`), which is product-shaped tuning on a shared component that-`spec:AST-002` does not admit, and which lets a caller write a cap the-viewport term cannot reason about.-### DEC-3 — Any control can open a menu**Reference:** `component:DropdownMenu/DEC-3`@@ -412,3 +393,49 @@ None.This file does not duplicate consumer prop tables, item examples, focus andpositioning algorithms, implementation steps, or shared modality, layer,dismissal, and theming rules. It links to their owners.++### DEC-6 — A titled group of rows is `DropdownMenuGroup`++**Reference:** `component:DropdownMenu/DEC-6`++**Decider:** `cixzhang`, 2026-10-03++Data mode could title a run of rows through `{type: 'section', title}` and+compound mode could not, so the menus that most need grouping — checkbox+rows, radio groups, rows mounted conditionally, all of which must be+compound — left a screen reader a run of loose rows where a sighted user saw+two clusters. The compound peer names its rows through `aria-labelledby` on+the visible heading and reuses the `dropdown-menu-section-heading` treatment,+so one heading looks and reads the same in both modes.++The component is named for the `role="group"` it renders. The data model+keeps `DropdownMenuSection` for its `{type: 'section'}` entry: the two words+describe the same concept, and one name across both would collide with that+exported type. Rejected: renaming the component to `DropdownMenuSection`,+which collides; renaming both, which breaks a public type for a wording+change.++`title` is `ReactNode`. A rich heading is a legitimate need, and the data+mode's string title is the narrower case rather than the model to match. A+focusable node inside a heading lands in the group but outside the roving+focus order, so the arrow keys cannot reach it; the type does not prevent+that and a case pins the behavior instead.++### DEC-7 — A safe triangle protects the diagonal to a flyout++**Reference:** `component:DropdownMenu/DEC-7`+**Decider:** `cixzhang`, `2026-10-02`++`menuMaxHeight` replaces only the 300px term of the cap; the viewport gutters+still bound the menu, so a menu that must show all of its rows (a docked phone+menu of eleven 44px rows) can, without ever overflowing the screen. The dynamic+value uses `100dvb` alone; every browser with anchor positioning has it.++A prop rather than a theme variable, because the need is situational — one+menu with many rows — rather than a product-wide preference, and a prop reads+more clearly at the callsite that has the problem.++The value is a number of pixels. Rejected: an arbitrary CSS length (`50vh`,+`calc(...)`), which is product-shaped tuning on a shared component that+`spec:AST-002` does not admit, and which lets a caller write a cap the+viewport term cannot reason about.diff --git a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx b/packages/core/src/DropdownMenu/DropdownMenu.test.tsxindex 2febe8eaf5..bebb2bf3bf 100644--- a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx+++ b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx@@ -18,6 +18,7 @@ import * as stylex from '@stylexjs/stylex';import {DropdownMenu} from './DropdownMenu';import {DropdownMenuItem} from './DropdownMenuItem';import {DropdownMenuDivider} from './DropdownMenuDivider';+import {DropdownMenuGroup} from './DropdownMenuGroup';import {Divider} from '../Divider';import {rtlStyles} from '../utils';import {__resetInteractionModalityForTest} from '../utils/interactionModality';@@ -1454,6 +1455,190 @@ describe('DropdownMenuItem ref', () => {});});+describe('DropdownMenuGroup (compound mode)', () => {+ it('a focusable node in the heading is not reachable by the arrow keys', async () => {+ // A heading is not a menu row, so a control inside one lands in the+ // group but outside the roving focus order. The type does not prevent+ // this — a rich heading is a legitimate need — so the behavior is+ // pinned rather than discovered.+ const user = userEvent.setup();+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuGroup+ title={+ <>+ Version history <button type="button">Info</button>+ </>+ }>+ <DropdownMenuItem label="Restore" onClick={() => {}} />+ <DropdownMenuItem label="Compare" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );+ await user.click(screen.getByRole('button', {name: /Actions/}));++ const menu = screen.getByRole('menu', {hidden: true});+ const info = screen.getByRole('button', {name: 'Info', hidden: true});+ const restore = screen.getByRole('menuitem', {+ name: 'Restore',+ hidden: true,+ });+ const compare = screen.getByRole('menuitem', {+ name: 'Compare',+ hidden: true,+ });++ restore.focus();+ fireEvent.keyDown(menu, {key: 'ArrowDown'});+ expect(compare).toHaveFocus();+ fireEvent.keyDown(menu, {key: 'ArrowDown'});+ expect(info).not.toHaveFocus();+ });++ it('arrow navigation steps across a group boundary as if the rows were flat', async () => {+ // The group renders a wrapper between the menu and its rows, which is+ // where flat navigation usually breaks.+ const user = userEvent.setup();+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuItem label="Open" onClick={() => {}} />+ <DropdownMenuGroup title="Version history">+ <DropdownMenuItem label="Restore" onClick={() => {}} />+ </DropdownMenuGroup>+ <DropdownMenuGroup title="Danger zone">+ <DropdownMenuItem label="Delete" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );+ await user.click(screen.getByRole('button', {name: /Actions/}));++ const menu = screen.getByRole('menu', {hidden: true});+ const row = (name: string) =>+ screen.getByRole('menuitem', {name, hidden: true});++ row('Open').focus();+ fireEvent.keyDown(menu, {key: 'ArrowDown'});+ expect(row('Restore')).toHaveFocus();+ fireEvent.keyDown(menu, {key: 'ArrowDown'});+ expect(row('Delete')).toHaveFocus();+ fireEvent.keyDown(menu, {key: 'ArrowUp'});+ expect(row('Restore')).toHaveFocus();+ });++ it('renders a role="group" named by its heading', () => {+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuGroup title="Version history">+ <DropdownMenuItem label="Restore" onClick={() => {}} />+ <DropdownMenuItem label="Compare" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );++ const group = screen.getByRole('group', {+ name: 'Version history',+ hidden: true,+ });+ const heading = screen.getByText('Version history');+ expect(group).toHaveAttribute('aria-labelledby', heading.id);+ expect(heading.id).not.toBe('');+ expect(group).toContainElement(+ screen.getByRole('menuitem', {name: 'Restore', hidden: true}),+ );+ });++ it('renders the heading with the data-mode theme class', () => {+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuGroup title="Version history">+ <DropdownMenuItem label="Restore" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );++ expect(screen.getByText('Version history')).toHaveClass(+ 'astryx-dropdown-menu-section-heading',+ );+ });++ it('the heading is not a menuitem and roving focus skips it', async () => {+ const user = userEvent.setup();+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuItem label="Edit" onClick={() => {}} />+ <DropdownMenuGroup title="Danger zone">+ <DropdownMenuItem label="Delete" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );+ await user.click(screen.getByRole('button', {name: /Actions/}));++ expect(screen.getByText('Danger zone')).not.toHaveAttribute('role');+ expect(screen.getAllByRole('menuitem', {hidden: true})).toHaveLength(2);++ const menu = screen.getByRole('menu', {hidden: true});+ screen.getByRole('menuitem', {name: 'Edit', hidden: true}).focus();+ fireEvent.keyDown(menu, {key: 'ArrowDown'});+ expect(+ screen.getByRole('menuitem', {name: 'Delete', hidden: true}),+ ).toHaveFocus();+ fireEvent.keyDown(menu, {key: 'ArrowUp'});+ expect(+ screen.getByRole('menuitem', {name: 'Edit', hidden: true}),+ ).toHaveFocus();+ });++ it('typeahead never lands on the heading', async () => {+ const user = userEvent.setup();+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuItem label="Edit" onClick={() => {}} />+ <DropdownMenuGroup title="Danger zone">+ <DropdownMenuItem label="Delete" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );+ await user.click(screen.getByRole('button', {name: /Actions/}));+ const menu = screen.getByRole('menu', {hidden: true});++ // "d" matches both the heading ("Danger zone") and the row ("Delete");+ // only the row is a menu item.+ fireEvent.keyDown(menu, {key: 'd'});+ expect(+ screen.getByRole('menuitem', {name: 'Delete', hidden: true}),+ ).toHaveFocus();+ });++ it('an untitled group is an unnamed role="group"', () => {+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuGroup>+ <DropdownMenuItem label="Only" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );+ const group = screen.getByRole('group', {hidden: true});+ expect(group).not.toHaveAttribute('aria-labelledby');+ expect(group.querySelector('.astryx-dropdown-menu-section-heading')).toBe(+ null,+ );+ });++ it('forwards a ref to the group element', () => {+ const ref = vi.fn();+ render(+ <DropdownMenu button={{label: 'Actions'}}>+ <DropdownMenuGroup title="T" ref={ref}>+ <DropdownMenuItem label="Only" onClick={() => {}} />+ </DropdownMenuGroup>+ </DropdownMenu>,+ );+ expect(ref).toHaveBeenCalledWith(+ screen.getByRole('group', {name: 'T', hidden: true}),+ );+ });+});+describe('DropdownMenu dividers', () => {it('renders dividers between items', () => {render(diff --git a/packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjs b/packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjsnew file mode 100644index 0000000000..87dcaaa42e--- /dev/null+++ b/packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjs@@ -0,0 +1,53 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */++export const docs = {+ name: 'DropdownMenuGroup',+ subComponentOf: 'DropdownMenu',+ displayName: 'Dropdown Menu Group',+ isHiddenFromOverview: true,+ playground: {+ // A standalone group has no required props, so the properties-tab preview+ // would render an empty box. Seed a title so the heading shows.+ defaults: {title: 'Version history'},+ },+ description:+ 'A titled group of rows in a compound menu. Renders role="group" named by its heading; the heading is plain text, not a menuitem, so arrow keys and typeahead skip it. The data-driven equivalent is the `{type: "section", title, items}` entry in `items`; the heading shares its typography and theme target.',+ props: [+ {+ name: 'title',+ type: 'ReactNode',+ description:+ "Heading shown above the rows and used as the group's accessible name. Omit for an unnamed group.",+ },+ {+ name: 'children',+ type: 'ReactNode',+ description:+ 'The rows of the group: DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuSubMenu.',+ },+ {+ name: 'xstyle',+ type: 'StyleXStyles',+ description:+ 'StyleX styles applied to the group wrapper. Must be a stylex.create() value: not an inline style object like style={{}}.',+ },+ ],+ theming: {+ targets: [{className: 'astryx-dropdown-menu-section-heading'}],+ },+};++export const docsDense = {+ name: 'DropdownMenuGroup',+ isHiddenFromOverview: true,+ displayName: 'Dropdown Menu Group',+ description:+ 'titled role="group" of rows for compound menus; compound peer of the data API\'s {type: "section"}',+ propDescriptions: {+ title: 'heading above the rows; names the group',+ children: 'the rows of the group',+ xstyle: 'StyleX styles applied to the group wrapper',+ },+};diff --git a/packages/core/src/DropdownMenu/DropdownMenuGroup.tsx b/packages/core/src/DropdownMenu/DropdownMenuGroup.tsxnew file mode 100644index 0000000000..6afd11be41--- /dev/null+++ b/packages/core/src/DropdownMenu/DropdownMenuGroup.tsx@@ -0,0 +1,117 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++'use client';++/**+ * @file DropdownMenuGroup.tsx+ * @input Uses spacing/typography/color tokens, themeProps (heading target)+ * @output Exports DropdownMenuGroup component and DropdownMenuGroupProps+ * @position Sub-component; used inside DropdownMenu+ *+ * The compound-mode peer of the data API's `{type: 'section', title, items}`+ * option: the same heading typography and `dropdown-menu-section-heading`+ * theme target, with the group named by its visible heading.+ *+ * SYNC: When modified, update these files to stay in sync:+ * - /packages/core/src/DropdownMenu/DropdownMenu.doc.mjs+ * - /packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjs+ * - /packages/core/src/DropdownMenu/DropdownMenu.test.tsx+ * - /packages/core/src/DropdownMenu/index.ts+ * - /packages/core/src/ContextMenu/index.ts+ * - /packages/core/src/Breadcrumbs/index.ts+ * - /apps/storybook/stories/DropdownMenu.stories.tsx+ * - /packages/cli/assets/templates/blocks/components/DropdownMenu/ (showcase blocks)+ */++import {useId, type ReactNode} from 'react';+import * as stylex from '@stylexjs/stylex';+import {+ colorVars,+ spacingVars,+ typographyVars,+ typeScaleVars,+} from '../theme/tokens.stylex';+import type {BaseProps} from '../BaseProps';+import {mergeProps} from '../utils';+import {themeProps} from '../utils/themeProps';++const styles = stylex.create({+ heading: {+ paddingBlock: spacingVars['--spacing-1'],+ paddingInline: spacingVars['--spacing-2'],+ fontFamily: typographyVars['--font-family-body'],+ fontSize: typeScaleVars['--text-supporting-size'],+ lineHeight: typeScaleVars['--text-supporting-leading'],+ color: colorVars['--color-text-secondary'],+ userSelect: 'none',+ },+});++export interface DropdownMenuGroupProps extends Pick<+ BaseProps,+ 'xstyle' | 'className' | 'style'+> {+ /**+ * Heading shown above the group's rows and used as the group's accessible+ * name (`aria-labelledby`). Omit it for an unnamed group.+ */+ title?: ReactNode;+ /** The rows of the group: menu items, selectable items, sub-menus. */+ children?: ReactNode;+ /** Ref forwarded to the `role="group"` element. */+ ref?: React.Ref<HTMLDivElement>;+}++/**+ * A titled group of menu rows.+ *+ * Renders `role="group"` named by its heading. The heading is plain text, not+ * a `menuitem`, so it is never a stop in the menu's arrow-key order and+ * typeahead never lands on it. The compound peer of+ * `{type: 'section', title, items}` in the `items` data API.+ *+ * @example+ * ```+ * <DropdownMenu button={{ label: 'Actions' }}>+ * <DropdownMenuGroup title="Version history">+ * <DropdownMenuItem label="Restore" onClick={handleRestore} />+ * <DropdownMenuItem label="Compare" onClick={handleCompare} />+ * </DropdownMenuGroup>+ * <DropdownMenuDivider />+ * <DropdownMenuItem label="Delete" variant="destructive" onClick={handleDelete} />+ * </DropdownMenu>+ * ```+ */+export function DropdownMenuGroup({+ title,+ children,+ xstyle,+ className,+ style,+ ref,+}: DropdownMenuGroupProps) {+ const headingId = useId();+ const hasTitle = title != null && title !== '' && title !== false;++ return (+ <div+ ref={ref}+ role="group"+ aria-labelledby={hasTitle ? headingId : undefined}+ {...mergeProps(stylex.props(xstyle), className, style)}>+ {hasTitle && (+ <div+ id={headingId}+ {...mergeProps(+ themeProps('dropdown-menu-section-heading'),+ stylex.props(styles.heading),+ )}>+ {title}+ </div>+ )}+ {children}+ </div>+ );+}++DropdownMenuGroup.displayName = 'DropdownMenuGroup';diff --git a/packages/core/src/DropdownMenu/index.ts b/packages/core/src/DropdownMenu/index.tsindex 777e86497a..a6d8f559b5 100644--- a/packages/core/src/DropdownMenu/index.ts+++ b/packages/core/src/DropdownMenu/index.ts@@ -39,6 +39,12 @@ export {type DropdownMenuDividerProps,} from './DropdownMenuDivider';+// Group — the compound peer of the data API's `{type: 'section', title}`.+export {+ DropdownMenuGroup,+ type DropdownMenuGroupProps,+} from './DropdownMenuGroup';+// Selectable items — checkbox (independent) and radio (single-select group).export {DropdownMenuCheckboxItem,