List
A vertical list of items, optionally selectable.
- **Plain** (selectable false): role="list" with listitems; item actions stay in the normal Tab order.
- **Selectable** (APG Listbox): role="listbox" with options and one Tab stop (the first selected option, else the first option). ArrowUp/Down move focus (wrapping), Home/End jump to the ends, typeahead is on for more than 7 items, Enter/Space and clicks toggle selection (a Space typed within 500 ms of a typeahead character continues the search instead; with Ctrl, Alt or Meta, Enter and Space are left to the page).
- **Selectable with item actions** (APG Grid): role="grid" with rows (carrying aria-selected) and gridcells for the content and the action. One Tab stop; Up/Down move between rows, Right/Left (mirrored in RTL) move into and out of the actions. A cell that holds a text-entry widget takes focus itself: Enter/F2 enter the widget, Escape returns to the cell. Clicks and keys that start inside an action, or inside a popup it opens (a Popover, a Menu), never toggle selection.
- **Navigation without selection** (navigationMode): 'items' makes the items of a plain list one Tab stop (the item that last had focus) with the listbox's arrow keys, Home/End and typeahead, keeping role="list"; 'composite' renders the grid above from the first render, for a selectable list too, so the items never remount when actions appear. The items of a list without selection carry no aria-selected. The resolved mode is data-navigation-mode.
- **Actions on the item itself** (List.Item onAction): clicks and Enter run it, and Space on an item that cannot be selected; in a selectable item it runs before the selection toggles, and its preventDefault() keeps the selection. List.Item disabledSelection keeps an item's selection as it is while the item stays focusable and in the arrow-key order.
- **Check marks** (checkmark, opt-in): a decorative check at the start of every item of a selectable list, shown while the item is selected; List.Item checkmark replaces or hides it.
- **Switching semantics remounts the items.** Listbox/list and grid use different elements (ul/li and div), so when a selectable list without a window gains its first item action, loses its last one, or selectable or navigationMode changes the structure, React remounts the items and their content: state inside them (an inline rename input's draft, an uncontrolled checkbox) is reset. Focus that is on an item or inside it when the list switches moves to the same item (by value, else by position; the next item when the focused one was removed), or to its first focusable content when the item is no Tab stop any more, so the switch never drops it to <body>. This includes focus inside the last action when that action removes itself (an inline rename input that unmounts on Enter). An action that removes itself while focused without causing a switch drops focus, like any removed element. When the list may switch, keep such state in the parent, or pin the grid with navigationMode="composite".
- Selection: selectionMode 'single' (default) or 'multiple'; controlled with selectedItems (or selectedItem in single mode) or uncontrolled with the default* props. Values of items that are no longer rendered are dropped from the reported selection (a windowed list keeps them).
- **Windowing** (virtualWindow and count, for long lists): a window from useVirtualWindow and a function child that returns the item at an index render only the items in view plus an overscan, with spacers for the others. The list element scrolls (give it a bounded height), every item has the window's item size as its height, the focused item stays rendered and is the Tab stop while focus is in the list, each item carries its place in the whole list, and the values selected outside the window stay selected. The keys move by index over the whole list (ArrowUp/ArrowDown, Home/End, and PageUp/PageDown by ten), scrolling the target into view before focusing it, rendered or not; typeahead matches the rendered items, or every item with getItemLabel. Its structure never follows the rendered items: a selectable windowed list is a listbox unless navigationMode="composite" pins the grid (pin it when items have actions; a development warning says so).
- Sub-component: List.Item (also exported as ListItem for React Server Components).
Examples
Default
- Apples
- Bananas
- Cherries
- Dates
export const Default: Story = {
render: (args) => (
<List {...args}>
<List.Item>Apples</List.Item>
<List.Item>Bananas</List.Item>
<List.Item>Cherries</List.Item>
<List.Item>Dates</List.Item>
</List>
),
};With Actions
- Document A
- Document B
- Document C
export const WithActions: Story = {
render: (args) => (
<List {...args}>
{['Document A', 'Document B', 'Document C'].map((name) => (
<List.Item
key={name}
action={
<Button appearance="subtle" size="small" className="text-wave-error">
Delete {name}
</Button>
}
>
{name}
</List.Item>
))}
</List>
),
};Single Select
Selected: none
- Item Alpha
- Item Beta
- Item Gamma
export const SingleSelect: Story = {
args: {
selectable: true,
'aria-label': 'Items',
onSelectionChange: fn(),
},
render: (args) => (
<SelectionDemo {...args}>
<List.Item value="a">Item Alpha</List.Item>
<List.Item value="b">Item Beta</List.Item>
<List.Item value="c">Item Gamma</List.Item>
</SelectionDemo>
),
};Multi Select
Selected: none
- Option One
- Option Two
- Option Three
- Option Four
export const MultiSelect: Story = {
args: {
selectable: true,
selectionMode: 'multiple',
'aria-label': 'Options',
onSelectionChange: fn(),
},
render: (args) => (
<SelectionDemo {...args}>
<List.Item value="1">Option One</List.Item>
<List.Item value="2">Option Two</List.Item>
<List.Item value="3">Option Three</List.Item>
<List.Item value="4">Option Four</List.Item>
</SelectionDemo>
),
};Selectable With Actions
Selected: none
export const SelectableWithActions: Story = {
args: {
selectable: true,
selectionMode: 'multiple',
'aria-label': 'Documents',
onSelectionChange: fn(),
},
render: (args) => (
<SelectionDemo {...args}>
{['Document A', 'Document B', 'Document C'].map((name) => (
<List.Item
key={name}
value={name}
action={
<Button appearance="subtle" size="small" className="text-wave-error">
Delete {name}
</Button>
}
>
{name}
</List.Item>
))}
</SelectionDemo>
),
};Navigation Modes
navigationMode="none"
- Document A
- Document B
- Document C
navigationMode="items"
- Document A
- Document B
- Document C
navigationMode="composite"
export const NavigationModes: Story = {
render: (args) => (
<div className="flex flex-col gap-6">
{(['none', 'items', 'composite'] as const).map((mode) => (
<div key={mode}>
<p className="mb-2 text-wave-body-1 font-semibold">{`navigationMode="${mode}"`}</p>
<List {...args} navigationMode={mode} aria-label={`Documents, ${mode} navigation`}>
{['Document A', 'Document B', 'Document C'].map((name) => (
<List.Item
key={name}
action={
<Button appearance="subtle" size="small">
{`Share ${name}`}
</Button>
}
>
{name}
</List.Item>
))}
</List>
</div>
))}
</div>
),
};On Action
Opened: nothing yet
- Budget.xlsx
- Roadmap.pptx
- Notes.docx
export const OnAction: Story = {
args: {
navigationMode: 'items',
'aria-label': 'Recent files',
},
render: ({ navigationMode, ...args }) => {
const [last, setLast] = React.useState<string | null>(null);
return (
<div>
<p className="mb-2 text-wave-body-1">Opened: {last ?? 'nothing yet'}</p>
<List {...args} navigationMode={navigationMode}>
{['Budget.xlsx', 'Roadmap.pptx', 'Notes.docx'].map((name) => (
<List.Item
key={name}
onAction={() => {
setLast(name);
onAction(name);
}}
>
{name}
</List.Item>
))}
</List>
</div>
);
},
};Disabled Selection
Selected: inbox
- Inbox (always selected)
- Drafts
- Archive (opens, cannot be selected)
- Trash
export const DisabledSelection: Story = {
args: {
selectable: true,
selectionMode: 'multiple',
defaultSelectedItems: ['inbox'],
'aria-label': 'Folders',
onSelectionChange: fn(),
},
render: (args) => (
<SelectionDemo {...args}>
<List.Item value="inbox" disabledSelection>
Inbox (always selected)
</List.Item>
<List.Item value="drafts">Drafts</List.Item>
<List.Item value="archive" disabledSelection onAction={() => onAction('archive')}>
Archive (opens, cannot be selected)
</List.Item>
<List.Item value="trash">Trash</List.Item>
</SelectionDemo>
),
};Windowed
Selected: 3 of 10,000 (file-2, file-5000, file-9999)
- File 1
- File 2
- File 3
- File 4
- File 5
- File 6
- File 7
- File 8
- File 9
- File 10
- File 11
- File 12
- File 13
- File 14
- File 15
- File 16
- File 17
- File 18
export const Windowed: Story = {
args: {
selectable: true,
selectionMode: 'multiple',
defaultSelectedItems: ['file-2', 'file-5000', 'file-9999'],
'aria-label': 'Files',
onSelectionChange: fn(),
},
render: (args) => <WindowedDemo {...args} />,
};Windowed Variable Heights
- Message 1. The build finished, but two of the check
- Message 2. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one story lost its accessible name. Both are sma
- Message 3. The build finished, but two of the checks that run after it need a second look b
- Message 4. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one story lost its accessible name. Both are small, and both are listed in the notes of
- Message 5. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle g
- Message 6. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one story lost its accessible name. Both are small, and both are listed in the notes of the pull request, with the places to loo
- Message 7. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one stor
- Message 8. The build finished, but two of the check
- Message 9. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one story lost its accessible name. Both are sma
- Message 10. The build finished, but two of the checks that run after it need a second look b
- Message 11. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one story lost its accessible name. Both are small, and both are listed in the notes of
- Message 12. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle g
- Message 13. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one story lost its accessible name. Both are small, and both are listed in the notes of the pull request, with the places to loo
- Message 14. The build finished, but two of the checks that run after it need a second look before the release goes out: the bundle grew by a few hundred bytes, and one stor
export const WindowedVariableHeights: Story = {
args: { 'aria-label': 'Messages' },
render: (args) => <MeasuredDemo {...args} />,
};Checkmarks
Selected: Apples, Cherries
- Apples
- Bananas
- Cherries
- Dates
export const Checkmarks: Story = {
args: {
selectable: true,
selectionMode: 'multiple',
checkmark: true,
defaultSelectedItems: ['Apples', 'Cherries'],
'aria-label': 'Fruit',
onSelectionChange: fn(),
},
render: (args) => (
<SelectionDemo {...args}>
{FRUIT.map((fruit) => (
<List.Item
key={fruit}
value={fruit}
checkmark={fruit === 'Dates' ? false : fruit === 'Bananas' ? '★' : undefined}
>
{fruit}
</List.Item>
))}
</SelectionDemo>
),
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
children | React.ReactNode | ((index: number) => React.ReactNode) | No | The items: | |
virtualWindow | VirtualWindow | No | Renders only the items in view, plus an overscan, of a long list: pass the result of The list element becomes the window's scroller (it scrolls vertically, without the browser's scroll anchoring): give it a bounded height, a height or a maximum height (a class or a style); without one the window measures the whole list and renders every item. Where the list navigates its items, one item is its Tab stop and the list element is none of its own ( Every item has the window's The item that has focus stays rendered when it is scrolled away (also while focus is in a popup it opened), so it keeps focus, and while focus is in the list it is the list's Tab stop. Once focus leaves the list it is no longer kept, and the Tab stop follows the rule of a list without focus among the rendered items (the first selected item, else the first item; in a list without selection the item that last had focus while it is rendered). When The keys move by index over the whole list, rendered or not, where the list navigates its items ( Selection covers every value: the values of items that are not rendered stay selected, and The structure never depends on which items are rendered: a selectable windowed list stays a listbox (its items are options) unless Applies only with | |
count | number | No | The number of items of a windowed list (with | |
getItemLabel | ((index: number) => string) | null | No | The text of the item at an index, for typeahead over every item of a windowed list (with | |
selectable | boolean | No | false | Whether list items can be selected. |
selectionMode | M | No | 'single' | Selection behavior when |
selectedItems | readonly string[] | No | Controlled array of selected item values (both modes). In single mode prefer | |
defaultSelectedItems | readonly string[] | No | [] | Default selected items for uncontrolled usage. |
onSelectionChange | (selected: string[]) => void | No | Called with the next array of selected values when the selection changes (both modes). | |
selectedItem | (M extends 'single' ? string) | null : never | No | Single mode: the controlled selected value ( | |
defaultSelectedItem | (M extends 'single' ? string) | null : never | No | Single mode: the initially selected value for uncontrolled usage. | |
onSelectedItemChange | M extends 'single' ? (item: string | null) => void : never | No | Single mode: called with the newly selected value, or | |
navigationMode | 'none' | 'items' | 'composite' | No | How the keyboard reaches the items. Unset, the list picks the mode itself: - The resolved mode is rendered as | |
checkmark | boolean | No | false | Draws a check mark at the start of every item of a selectable list, shown while the item is selected (decorative: |
ref | React.Ref<HTMLUListElement | HTMLDivElement> | No | Ref to the root element: a |
Any other prop is passed to the element it renders (HTMLUListElement).
Parts
List.Item
Stable class names
| Part | Class |
|---|---|
root | wave-list |
spacer | wave-list__spacer |