Skip to content

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

TypeScript

XDSDropdownMenu (#108)

Andrey Goder104c30bc56a3
diff --git a/apps/storybook/stories/DropdownMenu.stories.tsx b/apps/storybook/stories/DropdownMenu.stories.tsx
new file mode 100644
index 0000000000..0a561e8902
--- /dev/null
+++ b/apps/storybook/stories/DropdownMenu.stories.tsx
@@ -0,0 +1,301 @@
+import type {Meta, StoryObj} from '@storybook/react';
+import {useState} from 'react';
+import {XDSDropdownMenu, XDSDropdownMenuItem} from '@xds/core/DropdownMenu';
+import {
+ PencilIcon,
+ TrashIcon,
+ DocumentDuplicateIcon,
+ ArrowDownTrayIcon,
+ ShareIcon,
+ ArchiveBoxIcon,
+ FolderPlusIcon,
+ DocumentPlusIcon,
+ UserIcon,
+} from '@heroicons/react/24/outline';
+
+const meta: Meta<typeof XDSDropdownMenu> = {
+ title: 'Core/XDSDropdownMenu',
+ component: XDSDropdownMenu,
+ tags: ['autodocs'],
+ parameters: {
+ layout: 'centered',
+ },
+ argTypes: {
+ button: {
+ description: 'Props for customizing the trigger button',
+ },
+ items: {
+ description: 'Menu items (items, dividers, or sections)',
+ },
+ isMenuOpen: {
+ control: 'boolean',
+ description: 'Controlled open state',
+ },
+ menuWidth: {
+ control: 'text',
+ description: 'Custom menu width (number for px or CSS string)',
+ },
+ children: {
+ description: 'Custom render function for items',
+ },
+ 'data-testid': {
+ control: 'text',
+ description: 'Test ID for testing frameworks',
+ },
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof XDSDropdownMenu>;
+
+// Basic usage
+export const Default: Story = {
+ render: () => (
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[
+ {label: 'Edit', onClick: () => console.log('Edit clicked')},
+ {label: 'Duplicate', onClick: () => console.log('Duplicate clicked')},
+ {label: 'Delete', onClick: () => console.log('Delete clicked')},
+ ]}
+ />
+ ),
+};
+
+// With icons
+export const WithIcons: Story = {
+ render: () => (
+ <XDSDropdownMenu
+ button={{label: 'Actions', variant: 'primary'}}
+ items={[
+ {label: 'Edit', icon: PencilIcon, onClick: () => console.log('Edit')},
+ {
+ label: 'Duplicate',
+ icon: DocumentDuplicateIcon,
+ onClick: () => console.log('Duplicate'),
+ },
+ {
+ label: 'Download',
+ icon: ArrowDownTrayIcon,
+ onClick: () => console.log('Download'),
+ },
+ {
+ label: 'Delete',
+ icon: TrashIcon,
+ onClick: () => console.log('Delete'),
+ },
+ ]}
+ />
+ ),
+};
+
+// With sections
+export const WithSections: Story = {
+ render: () => (
+ <XDSDropdownMenu
+ button={{label: 'File', variant: 'ghost'}}
+ items={[
+ {
+ type: 'section',
+ title: 'Create',
+ items: [
+ {
+ label: 'New File',
+ icon: DocumentPlusIcon,
+ onClick: () => console.log('New File'),
+ },
+ {
+ label: 'New Folder',
+ icon: FolderPlusIcon,
+ onClick: () => console.log('New Folder'),
+ },
+ ],
+ },
+ {
+ type: 'section',
+ title: 'Share',
+ items: [
+ {
+ label: 'Share',
+ icon: ShareIcon,
+ onClick: () => console.log('Share'),
+ },
+ {
+ label: 'Archive',
+ icon: ArchiveBoxIcon,
+ onClick: () => console.log('Archive'),
+ },
+ ],
+ },
+ ]}
+ />
+ ),
+};
+
+// With dividers
+export const WithDividers: Story = {
+ render: () => (
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[
+ {label: 'Edit', onClick: () => console.log('Edit')},
+ {label: 'Duplicate', onClick: () => console.log('Duplicate')},
+ {type: 'divider'},
+ {label: 'Delete', onClick: () => console.log('Delete')},
+ ]}
+ />
+ ),
+};
+
+// With disabled items
+export const WithDisabledItems: Story = {
+ render: () => (
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[
+ {label: 'Edit', onClick: () => console.log('Edit')},
+ {label: 'Duplicate', onClick: () => console.log('Duplicate')},
+ {label: 'Delete (disabled)', disabled: true},
+ ]}
+ />
+ ),
+};
+
+// Controlled mode
+export const Controlled: Story = {
+ render: () => {
+ const [isOpen, setIsOpen] = useState(false);
+ return (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 16,
+ alignItems: 'center',
+ }}>
+ <div>Menu is {isOpen ? 'open' : 'closed'}</div>
+ <XDSDropdownMenu
+ button={{label: 'Controlled Menu'}}
+ isMenuOpen={isOpen}
+ onMenuToggle={setIsOpen}
+ items={[
+ {label: 'Item 1', onClick: () => console.log('Item 1')},
+ {label: 'Item 2', onClick: () => console.log('Item 2')},
+ {label: 'Item 3', onClick: () => console.log('Item 3')},
+ ]}
+ />
+ </div>
+ );
+ },
+};
+
+// Custom menu width
+export const CustomWidth: Story = {
+ render: () => (
+ <XDSDropdownMenu
+ button={{label: 'Wide Menu'}}
+ menuWidth={300}
+ items={[
+ {
+ label: 'This is a longer option that needs more space',
+ onClick: () => console.log('Option 1'),
+ },
+ {
+ label: 'Another long option with extra text',
+ onClick: () => console.log('Option 2'),
+ },
+ {label: 'Short one', onClick: () => console.log('Option 3')},
+ ]}
+ />
+ ),
+};
+
+// Button variants
+export const ButtonVariants: Story = {
+ render: () => (
+ <div style={{display: 'flex', gap: 16, flexWrap: 'wrap'}}>
+ <XDSDropdownMenu
+ button={{label: 'Secondary', variant: 'secondary'}}
+ items={[{label: 'Option 1'}, {label: 'Option 2'}]}
+ />
+ <XDSDropdownMenu
+ button={{label: 'Primary', variant: 'primary'}}
+ items={[{label: 'Option 1'}, {label: 'Option 2'}]}
+ />
+ <XDSDropdownMenu
+ button={{label: 'Ghost', variant: 'ghost'}}
+ items={[{label: 'Option 1'}, {label: 'Option 2'}]}
+ />
+ <XDSDropdownMenu
+ button={{label: 'Destructive', variant: 'destructive'}}
+ items={[{label: 'Option 1'}, {label: 'Option 2'}]}
+ />
+ </div>
+ ),
+};
+
+// Button sizes
+export const ButtonSizes: Story = {
+ render: () => (
+ <div style={{display: 'flex', gap: 16, alignItems: 'center'}}>
+ <XDSDropdownMenu
+ button={{label: 'Small', size: 'sm'}}
+ items={[{label: 'Option 1'}, {label: 'Option 2'}]}
+ />
+ <XDSDropdownMenu
+ button={{label: 'Medium', size: 'md'}}
+ items={[{label: 'Option 1'}, {label: 'Option 2'}]}
+ />
+ <XDSDropdownMenu
+ button={{label: 'Large', size: 'lg'}}
+ items={[{label: 'Option 1'}, {label: 'Option 2'}]}
+ />
+ </div>
+ ),
+};
+
+// With onClick callback
+export const WithOnClick: Story = {
+ render: () => {
+ const [clickCount, setClickCount] = useState(0);
+ return (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 16,
+ alignItems: 'center',
+ }}>
+ <div>Button clicked {clickCount} times</div>
+ <XDSDropdownMenu
+ button={{label: 'Click Me'}}
+ onClick={() => setClickCount(c => c + 1)}
+ items={[
+ {label: 'Menu Item', onClick: () => console.log('Item clicked')},
+ ]}
+ />
+ </div>
+ );
+ },
+};
+
+// Custom item rendering with XDSDropdownMenuItem
+export const CustomItemRender: Story = {
+ render: () => (
+ <XDSDropdownMenu
+ button={{label: 'Select User'}}
+ items={[
+ {label: 'Alice Johnson'},
+ {label: 'Bob Smith'},
+ {label: 'Carol Williams'},
+ ]}>
+ {item => (
+ <XDSDropdownMenuItem
+ icon={UserIcon}
+ label={item.label}
+ description={`${item.label.toLowerCase().replace(' ', '.')}@example.com`}
+ />
+ )}
+ </XDSDropdownMenu>
+ ),
+};
diff --git a/packages/core/src/DropdownMenu/README.md b/packages/core/src/DropdownMenu/README.md
new file mode 100644
index 0000000000..a992a9e2f2
--- /dev/null
+++ b/packages/core/src/DropdownMenu/README.md
@@ -0,0 +1,164 @@
+# /packages/core/src/DropdownMenu
+
+A dropdown menu component for displaying actionable items in a popup menu.
+
+<!-- SYNC: When files in this directory change, update this document. -->
+
+## Features
+
+- **Button customization**: Customize the trigger button via the `button` prop (supports all XDSButton props)
+- **Data-driven items**: Pass items via the `items` prop with support for sections and dividers
+- **Controlled/Uncontrolled**: Supports both controlled (`isMenuOpen`/`onMenuToggle`) and uncontrolled modes
+- **Custom menu width**: Override default width (matches button) via `menuWidth` prop
+- **Sections**: Group related items with optional headers using `XDSDropdownMenuSection`
+- **Keyboard navigation**: Full keyboard support (Arrow keys, Home, End, Enter, Space, Escape)
+- **Accessibility**: Proper ARIA roles (menu, menuitem) and attributes
+- **Custom rendering**: Optional `children` render function with `XDSDropdownMenuItem` helper
+
+## Usage
+
+```tsx
+import {XDSDropdownMenu, XDSDropdownMenuItem} from '@xds/core/DropdownMenu';
+
+// Basic usage
+<XDSDropdownMenu
+ button={{ label: 'Actions' }}
+ items={[
+ { label: 'Edit', onClick: () => handleEdit() },
+ { label: 'Delete', onClick: () => handleDelete() },
+ ]}
+/>
+
+// With icons
+<XDSDropdownMenu
+ button={{ label: 'Actions' }}
+ items={[
+ { label: 'Edit', icon: PencilIcon, onClick: () => handleEdit() },
+ { label: 'Delete', icon: TrashIcon, onClick: () => handleDelete() },
+ ]}
+/>
+
+// With sections
+<XDSDropdownMenu
+ button={{ label: 'File', variant: 'ghost' }}
+ items={[
+ {
+ type: 'section',
+ title: 'Create',
+ items: [
+ { label: 'New File', onClick: () => handleNew() },
+ { label: 'New Folder', onClick: () => handleNewFolder() },
+ ],
+ },
+ {
+ type: 'section',
+ title: 'Manage',
+ items: [
+ { label: 'Rename', onClick: () => handleRename() },
+ { label: 'Delete', disabled: true },
+ ],
+ },
+ ]}
+/>
+
+// With dividers
+<XDSDropdownMenu
+ button={{ label: 'Actions' }}
+ items={[
+ { label: 'Edit', onClick: () => handleEdit() },
+ { type: 'divider' },
+ { label: 'Delete', onClick: () => handleDelete() },
+ ]}
+/>
+
+// Controlled mode
+const [isOpen, setIsOpen] = useState(false);
+<XDSDropdownMenu
+ button={{ label: 'Options' }}
+ items={[...]}
+ isMenuOpen={isOpen}
+ onMenuToggle={setIsOpen}
+/>
+
+// Custom item rendering with XDSDropdownMenuItem
+<XDSDropdownMenu
+ button={{ label: 'Users' }}
+ items={users}
+>
+ {item => (
+ <XDSDropdownMenuItem
+ icon={item.icon}
+ label={item.label}
+ description={item.email}
+ />
+ )}
+</XDSDropdownMenu>
+```
+
+## Props
+
+### XDSDropdownMenu
+
+| Prop | Type | Default | Description |
+| -------------- | ---------------------------------------------- | ------------------- | ------------------------------------------------------------- |
+| `button` | `XDSDropdownMenuButtonProps` | `{ label: 'Menu' }` | Props for the trigger button (XDSButton props except onClick) |
+| `items` | `XDSDropdownMenuOption[]` | — | Menu items (items, dividers, or sections) |
+| `isMenuOpen` | `boolean` | — | Controlled open state |
+| `onMenuToggle` | `(isOpen: boolean) => void` | — | Callback when open state changes |
+| `menuWidth` | `number \| string` | — | Custom menu width (default: matches button) |
+| `onClick` | `() => void` | — | Callback when button is clicked |
+| `children` | `(item: XDSDropdownMenuItemData) => ReactNode` | — | Custom render function for items |
+
+### XDSDropdownMenuItem
+
+Helper component for custom item rendering with consistent styling.
+
+| Prop | Type | Default | Description |
+| ------------- | -------------- | ------- | ---------------------------------------------- |
+| `icon` | `XDSIconType` | — | Icon to display before the label |
+| `label` | `ReactNode` | — | Primary label text |
+| `description` | `ReactNode` | — | Secondary description text below the label |
+| `children` | `ReactNode` | — | Additional content after the label/description |
+| `xstyle` | `StyleXStyles` | — | StyleX styles for the root container |
+
+### XDSDropdownMenuItemData
+
+| Prop | Type | Default | Description |
+| ---------- | ------------- | ------- | -------------------------------- |
+| `label` | `string` | — | Display label for the item |
+| `onClick` | `() => void` | — | Callback when item is selected |
+| `disabled` | `boolean` | `false` | Whether the item is disabled |
+| `icon` | `XDSIconType` | — | Icon to display before the label |
+
+### XDSDropdownMenuDivider
+
+| Prop | Type | Value | Description |
+| ------ | ----------- | ----------- | ----------------- |
+| `type` | `'divider'` | `'divider'` | Indicates divider |
+
+### XDSDropdownMenuSection
+
+| Prop | Type | Default | Description |
+| ------- | --------------------------- | ------- | ----------------------- |
+| `type` | `'section'` | — | Indicates section |
+| `title` | `string` | — | Optional section header |
+| `items` | `XDSDropdownMenuItemData[]` | — | Items in the section |
+
+## Files
+
+| File | Role | Purpose |
+| -------------------------- | --------- | -------------------------------- |
+| `index.ts` | Entry | Exports components and types |
+| `XDSDropdownMenu.tsx` | Core | Main component implementation |
+| `XDSDropdownMenuItem.tsx` | Component | Helper for custom item rendering |
+| `XDSDropdownMenu.test.tsx` | Testing | Unit tests |
+
+## Implementation Notes
+
+- Uses `useXDSLayer` with `mode: 'context'` for CSS anchor positioning
+- Uses `XDSButton` internally with `ChevronDownIcon` that inherits button text color
+- Items are tracked via the `items` prop to enable keyboard navigation
+- Keyboard navigation skips disabled items
+- Light dismiss is enabled by default (clicking outside closes menu)
+- Focus returns to button when menu closes
+- `XDSDropdownMenuItem` provides consistent styling for custom item layouts
diff --git a/packages/core/src/DropdownMenu/XDSDropdownMenu.test.tsx b/packages/core/src/DropdownMenu/XDSDropdownMenu.test.tsx
new file mode 100644
index 0000000000..d529e3b199
--- /dev/null
+++ b/packages/core/src/DropdownMenu/XDSDropdownMenu.test.tsx
@@ -0,0 +1,352 @@
+/**
+ * @file XDSDropdownMenu.test.tsx
+ * @input Uses vitest, @testing-library/react, XDSDropdownMenu component
+ * @output Unit tests for XDSDropdownMenu component behavior
+ * @position Testing; validates XDSDropdownMenu.tsx implementation
+ *
+ * SYNC: When XDSDropdownMenu.tsx changes, update tests to match new behavior
+ */
+
+import {describe, it, expect, vi, beforeEach} from 'vitest';
+import {render, screen} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import {XDSDropdownMenu} from './XDSDropdownMenu';
+
+// Mock showPopover and hidePopover methods since they're not implemented in jsdom
+beforeEach(() => {
+ HTMLElement.prototype.showPopover = vi.fn(function (this: HTMLElement) {
+ this.setAttribute('popover-open', '');
+ const event = new Event('toggle', {bubbles: false});
+ Object.defineProperty(event, 'newState', {value: 'open'});
+ this.dispatchEvent(event);
+ });
+ HTMLElement.prototype.hidePopover = vi.fn(function (this: HTMLElement) {
+ this.removeAttribute('popover-open');
+ const event = new Event('toggle', {bubbles: false});
+ Object.defineProperty(event, 'newState', {value: 'closed'});
+ this.dispatchEvent(event);
+ });
+ const originalMatches = HTMLElement.prototype.matches;
+ HTMLElement.prototype.matches = function (selector: string) {
+ if (selector === ':popover-open') {
+ return this.hasAttribute('popover-open');
+ }
+ return originalMatches.call(this, selector);
+ };
+});
+
+describe('XDSDropdownMenu', () => {
+ it('renders trigger button with label', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ />,
+ );
+ expect(screen.getByRole('button', {name: /Actions/})).toBeInTheDocument();
+ });
+
+ it('renders menu with role="menu"', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ />,
+ );
+ expect(screen.getByRole('menu', {hidden: true})).toBeInTheDocument();
+ });
+
+ it('has aria-haspopup and aria-expanded attributes', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ />,
+ );
+ const button = screen.getByRole('button', {name: /Actions/});
+ expect(button).toHaveAttribute('aria-haspopup', 'menu');
+ expect(button).toHaveAttribute('aria-expanded', 'false');
+ });
+
+ it('opens menu when button is clicked', async () => {
+ const user = userEvent.setup();
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ />,
+ );
+
+ await user.click(screen.getByRole('button', {name: /Actions/}));
+ expect(HTMLElement.prototype.showPopover).toHaveBeenCalled();
+ });
+
+ it('calls onClick callback when button is clicked', async () => {
+ const user = userEvent.setup();
+ const handleClick = vi.fn();
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ onClick={handleClick}
+ />,
+ );
+
+ await user.click(screen.getByRole('button', {name: /Actions/}));
+ expect(handleClick).toHaveBeenCalledTimes(1);
+ });
+
+ it('applies data-testid to button', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ data-testid="my-dropdown"
+ />,
+ );
+ expect(screen.getByTestId('my-dropdown')).toBeInTheDocument();
+ });
+});
+
+describe('XDSDropdownMenu controlled mode', () => {
+ it('respects isMenuOpen prop', async () => {
+ const handleToggle = vi.fn();
+ const {rerender} = render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ isMenuOpen={false}
+ onMenuToggle={handleToggle}
+ />,
+ );
+
+ const button = screen.getByRole('button', {name: /Actions/});
+ expect(button).toHaveAttribute('aria-expanded', 'false');
+
+ rerender(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ isMenuOpen={true}
+ onMenuToggle={handleToggle}
+ />,
+ );
+
+ expect(HTMLElement.prototype.showPopover).toHaveBeenCalled();
+ });
+
+ it('calls onMenuToggle when button is clicked', async () => {
+ const user = userEvent.setup();
+ const handleToggle = vi.fn();
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Item 1'}]}
+ isMenuOpen={false}
+ onMenuToggle={handleToggle}
+ />,
+ );
+
+ await user.click(screen.getByRole('button', {name: /Actions/}));
+ expect(handleToggle).toHaveBeenCalledWith(true);
+ });
+});
+
+describe('XDSDropdownMenu items', () => {
+ it('renders items with labels', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Edit'}, {label: 'Delete'}]}
+ />,
+ );
+ expect(
+ screen.getByRole('menuitem', {name: 'Edit', hidden: true}),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('menuitem', {name: 'Delete', hidden: true}),
+ ).toBeInTheDocument();
+ });
+
+ it('calls onClick when item is clicked', async () => {
+ const user = userEvent.setup();
+ const handleClick = vi.fn();
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Edit', onClick: handleClick}]}
+ />,
+ );
+
+ await user.click(
+ screen.getByRole('menuitem', {name: 'Edit', hidden: true}),
+ );
+ expect(handleClick).toHaveBeenCalledTimes(1);
+ });
+
+ it('does not call onClick when disabled', async () => {
+ const user = userEvent.setup();
+ const handleClick = vi.fn();
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Edit', onClick: handleClick, disabled: true}]}
+ />,
+ );
+
+ await user.click(
+ screen.getByRole('menuitem', {name: 'Edit', hidden: true}),
+ );
+ expect(handleClick).not.toHaveBeenCalled();
+ });
+
+ it('has aria-disabled when disabled', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Edit', disabled: true}]}
+ />,
+ );
+ expect(
+ screen.getByRole('menuitem', {name: 'Edit', hidden: true}),
+ ).toHaveAttribute('aria-disabled', 'true');
+ });
+});
+
+describe('XDSDropdownMenu sections', () => {
+ it('renders section with title', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[
+ {
+ type: 'section',
+ title: 'File Actions',
+ items: [{label: 'New'}, {label: 'Open'}],
+ },
+ ]}
+ />,
+ );
+
+ expect(screen.getByText('File Actions')).toBeInTheDocument();
+ expect(
+ screen.getByRole('menuitem', {name: 'New', hidden: true}),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('menuitem', {name: 'Open', hidden: true}),
+ ).toBeInTheDocument();
+ });
+
+ it('renders section without title', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[
+ {
+ type: 'section',
+ items: [{label: 'Item 1'}, {label: 'Item 2'}],
+ },
+ ]}
+ />,
+ );
+
+ expect(
+ screen.getByRole('menuitem', {name: 'Item 1', hidden: true}),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('menuitem', {name: 'Item 2', hidden: true}),
+ ).toBeInTheDocument();
+ });
+
+ it('has role="group" with aria-label', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[
+ {
+ type: 'section',
+ title: 'My Section',
+ items: [{label: 'Item'}],
+ },
+ ]}
+ />,
+ );
+
+ const group = screen.getByRole('group', {name: 'My Section', hidden: true});
+ expect(group).toBeInTheDocument();
+ });
+});
+
+describe('XDSDropdownMenu dividers', () => {
+ it('renders dividers between items', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Edit'}, {type: 'divider'}, {label: 'Delete'}]}
+ />,
+ );
+
+ expect(
+ screen.getByRole('menuitem', {name: 'Edit', hidden: true}),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('menuitem', {name: 'Delete', hidden: true}),
+ ).toBeInTheDocument();
+ expect(screen.getByRole('separator', {hidden: true})).toBeInTheDocument();
+ });
+});
+
+describe('XDSDropdownMenu button customization', () => {
+ it('renders with different button variants', () => {
+ const {rerender} = render(
+ <XDSDropdownMenu
+ button={{label: 'Primary', variant: 'primary'}}
+ items={[{label: 'Item'}]}
+ />,
+ );
+ expect(screen.getByRole('button', {name: /Primary/})).toBeInTheDocument();
+
+ rerender(
+ <XDSDropdownMenu
+ button={{label: 'Ghost', variant: 'ghost'}}
+ items={[{label: 'Item'}]}
+ />,
+ );
+ expect(screen.getByRole('button', {name: /Ghost/})).toBeInTheDocument();
+ });
+
+ it('renders with different button sizes', () => {
+ const {rerender} = render(
+ <XDSDropdownMenu
+ button={{label: 'Small', size: 'sm'}}
+ items={[{label: 'Item'}]}
+ />,
+ );
+ expect(screen.getByRole('button', {name: /Small/})).toBeInTheDocument();
+
+ rerender(
+ <XDSDropdownMenu
+ button={{label: 'Large', size: 'lg'}}
+ items={[{label: 'Item'}]}
+ />,
+ );
+ expect(screen.getByRole('button', {name: /Large/})).toBeInTheDocument();
+ });
+});
+
+describe('XDSDropdownMenu custom render', () => {
+ it('supports custom item rendering via children prop', () => {
+ render(
+ <XDSDropdownMenu
+ button={{label: 'Actions'}}
+ items={[{label: 'Edit'}, {label: 'Delete'}]}>
+ {item => (
+ <span data-testid={`custom-${item.label}`}>{item.label}!</span>
+ )}
+ </XDSDropdownMenu>,
+ );
+
+ expect(screen.getByTestId('custom-Edit')).toBeInTheDocument();
+ expect(screen.getByTestId('custom-Delete')).toBeInTheDocument();
+ });
+});
diff --git a/packages/core/src/DropdownMenu/XDSDropdownMenu.tsx b/packages/core/src/DropdownMenu/XDSDropdownMenu.tsx
new file mode 100644
index 0000000000..48e588c4df
--- /dev/null
+++ b/packages/core/src/DropdownMenu/XDSDropdownMenu.tsx
@@ -0,0 +1,595 @@
+/**
+ * @file XDSDropdownMenu.tsx
+ * @input Uses React, StyleX, useXDSLayer, XDSButton, XDSIcon
+ * @output Exports XDSDropdownMenu component
+ * @position Core implementation; consumed by index.ts
+ *
+ * SYNC: When modified, update:
+ * - /packages/core/src/DropdownMenu/README.md
+ * - /packages/core/src/DropdownMenu/index.ts
+ */
+
+import React, {
+ useCallback,
+ useId,
+ useMemo,
+ useRef,
+ useState,
+ type ReactNode,
+} from 'react';
+import * as stylex from '@stylexjs/stylex';
+import {useXDSLayer} from '../Layer/useXDSLayer';
+import {XDSButton, type XDSButtonProps} from '../Button';
+import {XDSIcon} from '../Icon';
+import type {XDSIconType} from '../Icon';
+import {ChevronDownIcon} from '@heroicons/react/16/solid';
+import {XDSDivider} from '../Divider';
+import {XDSDropdownMenuItem} from './XDSDropdownMenuItem';
+import {
+ colorVars,
+ spacingVars,
+ radiusVars,
+ transitionVars,
+ typographyVars,
+ textSizeVars,
+} from '../theme/tokens.stylex';
+
+const styles = stylex.create({
+ // Dropdown container
+ dropdown: {
+ boxSizing: 'border-box',
+ maxHeight: '300px',
+ overflowY: 'auto',
+ padding: spacingVars['--spacing-1'],
+ borderRadius: radiusVars['--radius-element'],
+ backgroundColor: colorVars['--color-surface'],
+ boxShadow: `0 4px 12px ${colorVars['--color-shadow-elevation']}`,
+ opacity: 1,
+ transition: `opacity ${transitionVars['--transition-fast']}`,
+ },
+
+ // Popover container (for anchor positioning)
+ popover: {
+ minWidth: 'anchor-size(width)',
+ },
+
+ // Custom width popover
+ popoverCustomWidth: (width: string | number) => ({
+ minWidth: typeof width === 'number' ? `${width}px` : width,
+ }),
+
+ // Section divider with label
+ sectionDivider: {
+ marginBlock: spacingVars['--spacing-1'],
+ },
+
+ // Divider
+ divider: {
+ marginBlock: spacingVars['--spacing-1'],
+ },
+
+ // Individual item
+ item: {
+ boxSizing: 'border-box',
+ display: 'flex',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-2'],
+ width: '100%',
+ padding: spacingVars['--spacing-2'],
+ borderRadius: radiusVars['--radius-content'],
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-base'],
+ color: colorVars['--color-text-primary'],
+ backgroundColor: 'transparent',
+ border: 'none',
+ cursor: 'pointer',
+ textAlign: 'left',
+ outline: 'none',
+ },
+ itemHighlighted: {
+ backgroundColor: colorVars['--color-hover-overlay'],
+ },
+ itemDisabled: {
+ opacity: 0.5,
+ cursor: 'not-allowed',
+ },
+
+ // Chevron icon styling
+ chevronIcon: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ },
+});
+
+// =============================================================================
+// Types
+// =============================================================================
+
+/**
+ * A menu item in the dropdown
+ */
+export interface XDSDropdownMenuItemData {
+ /**
+ * Display label for the item.
+ */
+ label: string;
+
+ /**
+ * Callback when item is selected.
+ */
+ onClick?: () => void;
+
+ /**
+ * Whether the item is disabled.
+ */
+ disabled?: boolean;
+
+ /**
+ * Icon to display before the label.
+ */
+ icon?: XDSIconType;
+}
+
+/**
+ * A divider between items
+ */
+export interface XDSDropdownMenuDivider {
+ type: 'divider';
+}
+
+/**
+ * A section/group of items with optional title
+ */
+export interface XDSDropdownMenuSection {
+ type: 'section';
+ title?: string;
+ items: XDSDropdownMenuItemData[];
+}
+
+/**
+ * Union of all menu option types
+ */
+export type XDSDropdownMenuOption =
+ | XDSDropdownMenuItemData
+ | XDSDropdownMenuDivider
+ | XDSDropdownMenuSection;
+
+// =============================================================================
+// Type guards and utilities
+// =============================================================================
+
+function isItemData(
+ option: XDSDropdownMenuOption,
+): option is XDSDropdownMenuItemData {
+ return !('type' in option);
+}
+
+function isDivider(
+ option: XDSDropdownMenuOption,
+): option is XDSDropdownMenuDivider {
+ return 'type' in option && option.type === 'divider';
+}
+
+function isSection(
+ option: XDSDropdownMenuOption,
+): option is XDSDropdownMenuSection {
+ return 'type' in option && option.type === 'section';
+}
+
+/**
+ * Get all selectable items from options (flattening sections)
+ */
+function getSelectableItems(
+ options: XDSDropdownMenuOption[],
+): XDSDropdownMenuItemData[] {
+ const items: XDSDropdownMenuItemData[] = [];
+
+ for (const option of options) {
+ if (isItemData(option)) {
+ items.push(option);
+ } else if (isSection(option)) {
+ for (const item of option.items) {
+ items.push(item);
+ }
+ }
+ }
+
+ return items;
+}
+
+// =============================================================================
+// Props
+// =============================================================================
+
+/**
+ * Props for customizing the dropdown button.
+ * Extends XDSButtonProps but omits onClick, href since those are managed internally.
+ */
+export type XDSDropdownMenuButtonProps = Omit<
+ XDSButtonProps,
+ 'onClick' | 'children'
+>;
+
+export interface XDSDropdownMenuProps {
+ /**
+ * Props for customizing the trigger button.
+ * Uses XDSButton internally - supports label, variant, size, icon, etc.
+ */
+ button?: XDSDropdownMenuButtonProps;
+
+ /**
+ * The items to display in the menu.
+ * Can be item objects, dividers, or sections.
+ */
+ items: XDSDropdownMenuOption[];
+
+ /**
+ * Whether the menu is open (controlled mode).
+ */
+ isMenuOpen?: boolean;
+
+ /**
+ * Callback when menu open state changes (controlled mode).
+ */
+ onMenuToggle?: (isOpen: boolean) => void;
+
+ /**
+ * Width of the dropdown menu.
+ * By default matches the button width.
+ * Can be a number (pixels) or CSS string value.
+ */
+ menuWidth?: number | string;
+
+ /**
+ * Callback when the button is clicked.
+ */
+ onClick?: () => void;
+
+ /**
+ * Custom render function for items.
+ * Only called for selectable items (not dividers/sections).
+ */
+ children?: (item: XDSDropdownMenuItemData) => ReactNode;
+
+ /**
+ * Test ID for testing frameworks.
+ */
+ 'data-testid'?: string;
+}
+
+// =============================================================================
+// Default item renderer
+// =============================================================================
+
+function DefaultItem({item}: {item: XDSDropdownMenuItemData}) {
+ return <XDSDropdownMenuItem icon={item.icon} label={item.label} />;
+}
+
+// =============================================================================
+// XDSDropdownMenu
+// =============================================================================
+
+/**
+ * A dropdown menu component that displays a list of actionable items.
+ *
+ * Unlike XDSSelector, this component has no inherent selector state -
+ * it's purely for displaying a menu of clickable items.
+ *
+ * @example
+ * ```tsx
+ * <XDSDropdownMenu
+ * button={{ label: 'Actions' }}
+ * items={[
+ * { label: 'Edit', onClick: () => handleEdit() },
+ * { label: 'Delete', onClick: () => handleDelete() },
+ * ]}
+ * />
+ * ```
+ */
+export function XDSDropdownMenu({
+ button = {label: 'Menu'},
+ items,
+ isMenuOpen: controlledIsOpen,
+ onMenuToggle,
+ menuWidth,
+ onClick,
+ children,
+ 'data-testid': testId,
+}: XDSDropdownMenuProps) {
+ const menuId = useId();
+ const buttonRef = useRef<HTMLButtonElement>(null);
+
+ // Internal state for uncontrolled mode
+ const [internalIsOpen, setInternalIsOpen] = useState(false);
+
+ // Determine if controlled or uncontrolled
+ const isControlled = controlledIsOpen !== undefined;
+ const isOpen = isControlled ? controlledIsOpen : internalIsOpen;
+
+ // Highlighted item for keyboard navigation
+ const [highlightedIndex, setHighlightedIndex] = useState(-1);
+
+ // Flatten items for keyboard navigation
+ const selectableItems = useMemo(() => getSelectableItems(items), [items]);
+
+ // Layer for dropdown positioning
+ const layer = useXDSLayer({
+ mode: 'context',
+ lightDismiss: true,
+ onHide: () => {
+ if (isControlled) {
+ onMenuToggle?.(false);
+ } else {
+ setInternalIsOpen(false);
+ }
+ setHighlightedIndex(-1);
+ buttonRef.current?.focus();
+ },
+ onShow: () => {
+ if (isControlled) {
+ onMenuToggle?.(true);
+ } else {
+ setInternalIsOpen(true);
+ }
+ },
+ });
+
+ // Sync layer with controlled state
+ React.useEffect(() => {
+ if (isControlled) {
+ if (controlledIsOpen && !layer.isOpen) {
+ layer.show();
+ } else if (!controlledIsOpen && layer.isOpen) {
+ layer.hide();
+ }
+ }
+ }, [controlledIsOpen, isControlled, layer]);
+
+ const handleButtonClick = useCallback(() => {
+ onClick?.();
+ if (isControlled) {
+ onMenuToggle?.(!controlledIsOpen);
+ } else {
+ if (layer.isOpen) {
+ layer.hide();
+ } else {
+ layer.show();
+ }
+ }
+ }, [onClick, isControlled, onMenuToggle, controlledIsOpen, layer]);
+
+ const closeMenu = useCallback(() => {
+ layer.hide();
+ }, [layer]);
+
+ // Generate item ID for accessibility
+ const getItemId = useCallback(
+ (index: number) => `${menuId}-item-${index}`,
+ [menuId],
+ );
+
+ // Handle item click
+ const handleItemClick = useCallback(
+ (item: XDSDropdownMenuItemData) => {
+ if (item.disabled) return;
+ item.onClick?.();
+ closeMenu();
+ },
+ [closeMenu],
+ );
+
+ // Handle item mouse enter
+ const handleItemMouseEnter = useCallback(
+ (item: XDSDropdownMenuItemData, index: number) => {
+ if (item.disabled) return;
+ setHighlightedIndex(index);
+ },
+ [],
+ );
+
+ // Keyboard navigation
+ const handleKeyDown = useCallback(
+ (e: React.KeyboardEvent) => {
+ if (!layer.isOpen) {
+ if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {
+ e.preventDefault();
+ layer.show();
+ setHighlightedIndex(0);
+ }
+ return;
+ }
+
+ switch (e.key) {
+ case 'ArrowDown':
+ e.preventDefault();
+ setHighlightedIndex(prev => {
+ let next = prev + 1;
+ // Skip disabled items
+ while (
+ next < selectableItems.length &&
+ selectableItems[next].disabled
+ ) {
+ next++;
+ }
+ return next < selectableItems.length ? next : prev;
+ });
+ break;
+ case 'ArrowUp':
+ e.preventDefault();
+ setHighlightedIndex(prev => {
+ let next = prev - 1;
+ // Skip disabled items
+ while (next >= 0 && selectableItems[next].disabled) {
+ next--;
+ }
+ return next >= 0 ? next : prev;
+ });
+ break;
+ case 'Home':
+ e.preventDefault();
+ {
+ let index = 0;
+ while (
+ index < selectableItems.length &&
+ selectableItems[index].disabled
+ ) {
+ index++;
+ }
+ setHighlightedIndex(index < selectableItems.length ? index : -1);
+ }
+ break;
+ case 'End':
+ e.preventDefault();
+ {
+ let index = selectableItems.length - 1;
+ while (index >= 0 && selectableItems[index].disabled) {
+ index--;
+ }
+ setHighlightedIndex(index >= 0 ? index : -1);
+ }
+ break;
+ case 'Escape':
+ e.preventDefault();
+ closeMenu();
+ break;
+ case 'Enter':
+ case ' ':
+ e.preventDefault();
+ if (
+ highlightedIndex >= 0 &&
+ highlightedIndex < selectableItems.length
+ ) {
+ handleItemClick(selectableItems[highlightedIndex]);
+ }
+ break;
+ }
+ },
+ [layer, selectableItems, highlightedIndex, closeMenu, handleItemClick],
+ );
+
+ // Render an individual item
+ const renderItem = useCallback(
+ (item: XDSDropdownMenuItemData, flatIndex: number) => {
+ const isHighlighted = flatIndex === highlightedIndex;
+
+ return (
+ <div
+ key={`${item.label}-${flatIndex}`}
+ id={getItemId(flatIndex)}
+ role="menuitem"
+ tabIndex={-1}
+ aria-disabled={item.disabled}
+ onClick={() => handleItemClick(item)}
+ onMouseEnter={() => handleItemMouseEnter(item, flatIndex)}
+ {...stylex.props(
+ styles.item,
+ isHighlighted && styles.itemHighlighted,
+ item.disabled && styles.itemDisabled,
+ )}>
+ {children ? children(item) : <DefaultItem item={item} />}
+ </div>
+ );
+ },
+ [
+ children,
+ highlightedIndex,
+ getItemId,
+ handleItemClick,
+ handleItemMouseEnter,
+ ],
+ );
+
+ // Render all options (handling sections/dividers)
+ const renderOptions = useCallback(() => {
+ let flatIndex = 0;
+ const elements: ReactNode[] = [];
+
+ for (let i = 0; i < items.length; i++) {
+ const option = items[i];
+
+ if (isDivider(option)) {
+ elements.push(
+ <XDSDivider key={`divider-${i}`} xstyle={styles.divider} />,
+ );
+ } else if (isSection(option)) {
+ const sectionItems: ReactNode[] = [];
+ for (const item of option.items) {
+ sectionItems.push(renderItem(item, flatIndex));
+ flatIndex++;
+ }
+ if (option.title) {
+ elements.push(
+ <XDSDivider
+ key={`section-divider-${i}`}
+ label={option.title}
+ xstyle={styles.sectionDivider}
+ />,
+ );
+ }
+ elements.push(
+ <div key={`section-${i}`} role="group" aria-label={option.title}>
+ {sectionItems}
+ </div>,
+ );
+ } else if (isItemData(option)) {
+ elements.push(renderItem(option, flatIndex));
+ flatIndex++;
+ }
+ }
+
+ return elements;
+ }, [items, renderItem]);
+
+ // Build chevron icon - inherits color from button text
+ const chevronIcon = (
+ <span {...stylex.props(styles.chevronIcon)}>
+ <XDSIcon icon={ChevronDownIcon} size="sm" color="inherit" />
+ </span>
+ );
+
+ // Determine popover xstyle
+ const popoverXstyle = menuWidth
+ ? styles.popoverCustomWidth(menuWidth)
+ : styles.popover;
+
+ return (
+ <>
+ <XDSButton
+ ref={el => {
+ (
+ buttonRef as React.MutableRefObject<HTMLButtonElement | null>
+ ).current = el;
+ layer.ref(el);
+ }}
+ {...button}
+ onClick={handleButtonClick}
+ onKeyDown={handleKeyDown}
+ aria-haspopup="menu"
+ aria-expanded={isOpen}
+ aria-controls={menuId}
+ aria-activedescendant={
+ isOpen && highlightedIndex >= 0
+ ? getItemId(highlightedIndex)
+ : undefined
+ }
+ data-testid={testId}>
+ {button.label}
+ {chevronIcon}
+ </XDSButton>
+
+ {layer.render(
+ <div id={menuId} role="menu" {...stylex.props(styles.dropdown)}>
+ {renderOptions()}
+ </div>,
+ {
+ placement: 'below',
+ alignment: 'start',
+ xstyle: popoverXstyle,
+ },
+ )}
+ </>
+ );
+}
+
+XDSDropdownMenu.displayName = 'XDSDropdownMenu';
diff --git a/packages/core/src/DropdownMenu/XDSDropdownMenuItem.tsx b/packages/core/src/DropdownMenu/XDSDropdownMenuItem.tsx
new file mode 100644
index 0000000000..a3adc34cde
--- /dev/null
+++ b/packages/core/src/DropdownMenu/XDSDropdownMenuItem.tsx
@@ -0,0 +1,112 @@
+/**
+ * @file XDSDropdownMenuItem.tsx
+ * @output Exports XDSDropdownMenuItem component for custom item rendering
+ * @position Sub-component; used by XDSDropdownMenu and consumers for custom items
+ *
+ * SYNC: When modified, update:
+ * - /packages/core/src/DropdownMenu/README.md
+ * - /packages/core/src/DropdownMenu/index.ts
+ */
+
+import type {ReactNode} from 'react';
+import * as stylex from '@stylexjs/stylex';
+import type {StyleXStyles} from '@stylexjs/stylex';
+import {XDSIcon} from '../Icon';
+import type {XDSIconType} from '../Icon';
+import {XDSText} from '../Text';
+import {spacingVars} from '../theme/tokens.stylex';
+
+const styles = stylex.create({
+ root: {
+ display: 'flex',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-2'],
+ flex: 1,
+ minWidth: 0,
+ },
+ content: {
+ display: 'flex',
+ flexDirection: 'column',
+ flex: 1,
+ minWidth: 0,
+ },
+});
+
+export interface XDSDropdownMenuItemProps {
+ /**
+ * Icon to display before the label.
+ */
+ icon?: XDSIconType;
+
+ /**
+ * Primary label text.
+ */
+ label: ReactNode;
+
+ /**
+ * Secondary description text displayed below the label.
+ */
+ description?: ReactNode;
+
+ /**
+ * Additional content to render after the label/description.
+ */
+ children?: ReactNode;
+
+ /**
+ * StyleX styles for the root container.
+ */
+ xstyle?: StyleXStyles;
+}
+
+/**
+ * A helper component for rendering custom dropdown menu items with consistent styling.
+ *
+ * Use this inside the `children` render prop of XDSDropdownMenu to create
+ * custom item layouts while maintaining design system consistency.
+ *
+ * @example
+ * ```tsx
+ * <XDSDropdownMenu
+ * button={{ label: 'Actions' }}
+ * items={actions}>
+ * {item => (
+ * <XDSDropdownMenuItem
+ * icon={item.icon}
+ * label={item.label}
+ * description={item.description}
+ * />
+ * )}
+ * </XDSDropdownMenu>
+ * ```
+ */
+export function XDSDropdownMenuItem({
+ icon,
+ label,
+ description,
+ children,
+ xstyle,
+}: XDSDropdownMenuItemProps) {
+ return (
+ <span {...stylex.props(styles.root, xstyle)}>
+ {icon && <XDSIcon icon={icon} size="sm" color="secondary" />}
+ <span {...stylex.props(styles.content)}>
+ {typeof label === 'string' ? (
+ <XDSText type="body" maxLines={1}>
+ {label}
+ </XDSText>
+ ) : (
+ label
+ )}
+ {description && (
+ <XDSText type="supporting" maxLines={1}>
+ {description}
+ </XDSText>
+ )}
+ </span>
+ {children}
+ </span>
+ );
+}
+
+XDSDropdownMenuItem.displayName = 'XDSDropdownMenuItem';
diff --git a/packages/core/src/DropdownMenu/index.ts b/packages/core/src/DropdownMenu/index.ts
new file mode 100644
index 0000000000..add393aacd
--- /dev/null
+++ b/packages/core/src/DropdownMenu/index.ts
@@ -0,0 +1,20 @@
+/**
+ * @file index.ts
+ * @output Exports XDSDropdownMenu, XDSDropdownMenuItem and related types
+ * @position Public API entry point
+ */
+
+export {
+ XDSDropdownMenu,
+ type XDSDropdownMenuProps,
+ type XDSDropdownMenuButtonProps,
+ type XDSDropdownMenuItemData,
+ type XDSDropdownMenuDivider,
+ type XDSDropdownMenuSection,
+ type XDSDropdownMenuOption,
+} from './XDSDropdownMenu';
+
+export {
+ XDSDropdownMenuItem,
+ type XDSDropdownMenuItemProps,
+} from './XDSDropdownMenuItem';
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 843d7ac73e..33121b3e52 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -32,6 +32,7 @@ export * from './TimeInput';
export * from './NumberInput';
export * from './Table';
export * from './Dialog';
+export * from './DropdownMenu';
export * from './TopNav';
// Layout utilities and components (includes XDSHStack, XDSVStack)