Skip to content

List

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

Document A
Document B
Document C
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"

Document A
Document B
Document C
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

NameTypeRequiredDefaultDescription
childrenReact.ReactNode | ((index: number) => React.ReactNode)No

The items: List.Item elements. In a windowed list (virtualWindow and count), a function (index) => <List.Item … /> that returns the item at an index: the list calls it for the rendered indexes only and keys each item by its index. Without virtualWindow and count a function renders nothing (a development warning says so).

virtualWindowVirtualWindowNo

Renders only the items in view, plus an overscan, of a long list: pass the result of useVirtualWindow({ itemSize }) (or an object of your own that implements VirtualWindow) with count, and a function child that returns the List.Item at an index. The items that are not rendered are replaced by spacers (aria-hidden, data-virtual-spacer) of their height.

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 (tabIndex -1, as Firefox would stop on a scroller); a plain windowed list keeps the browser's default, under which WebKit does not let the keyboard reach and scroll it: pass tabIndex={0} or navigate its items (navigationMode="items"). A tabIndex you pass wins.

Every item has the window's itemSize as its height (the list sets it, after the item's own style), so an item's content must fit in it. With a window that measures its rows (useVirtualWindow({ itemSize, measureItems: true }), itemSize being the estimate) an item has the height of its content instead, and carries the window's itemProps. Each item carries data-index (its 0-based index) and its place in the whole list: aria-setsize and aria-posinset, or in a grid (navigationMode="composite") the list's aria-rowcount and the row's aria-rowindex.

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 count drops to or below the focused item, focus moves to the last item.

The keys move by index over the whole list, rendered or not, where the list navigates its items (navigationMode 'items' or 'composite', or a selectable list): ArrowUp/ArrowDown (wrapping at the ends), Home/End, and PageUp/PageDown, which move ten items and stop at the ends. The target is scrolled into view before it is focused, the least that shows it whole: a rendered one by the browser (scrollIntoView, nearest), which the window follows, one that is not rendered through the window's scrollToIndex, and focused once it renders. An item that a pointer press focuses is not scrolled. Typeahead matches the labels of the rendered items only, unless getItemLabel gives the label of every item.

Selection covers every value: the values of items that are not rendered stay selected, and onSelectionChange reports them (a list without a window drops the values of items it no longer renders).

The structure never depends on which items are rendered: a selectable windowed list stays a listbox (its items are options) unless navigationMode="composite" makes it a grid from the first render, so scrolling never replaces the list element (which would reset its scroll position and remount every item). Its items' actions do not switch it to a grid as they do in a list without a window: an item with an action in a selectable windowed list without that pin is a development warning, since an option cannot hold interactive content. Pin navigationMode="composite" when items have actions.

Applies only with count and a function child; otherwise it is ignored, with a development warning.

countnumberNo

The number of items of a windowed list (with virtualWindow): the function child is called for the indexes from 0 to count - 1 that are rendered. A value that is not a whole number counts as its whole part, and one below 0 (or not finite) as 0.

getItemLabel((index: number) => string) | nullNo

The text of the item at an index, for typeahead over every item of a windowed list (with virtualWindow and count; ignored without them): typed characters move focus to the next item, from the focused one and wrapping around, whose label starts with them (case-insensitive, as in a list without a window), whether or not it is rendered. A target that is not rendered is scrolled into view and focused once it renders, as a key's target is. It is called for every index of the list while a character is typed (up to count calls per key), so keep it cheap, and return null, undefined or an empty string for an item that typeahead skips. Without it a windowed list matches the labels of its rendered items only. Fluent has no counterpart (its List has no typeahead).

selectablebooleanNofalse

Whether list items can be selected.

selectionModeMNo'single'

Selection behavior when selectable is true.

selectedItemsreadonly string[]No

Controlled array of selected item values (both modes). In single mode prefer selectedItem; a single-selection list that receives several values warns in development.

defaultSelectedItemsreadonly string[]No[]

Default selected items for uncontrolled usage.

onSelectionChange(selected: string[]) => voidNo

Called with the next array of selected values when the selection changes (both modes).

selectedItem(M extends 'single' ? string) | null : neverNo

Single mode: the controlled selected value (null: nothing selected).

defaultSelectedItem(M extends 'single' ? string) | null : neverNo

Single mode: the initially selected value for uncontrolled usage.

onSelectedItemChangeM extends 'single' ? (item: string | null) => void : neverNo

Single mode: called with the newly selected value, or null when it was deselected.

navigationMode'none' | 'items' | 'composite'No

How the keyboard reaches the items. Unset, the list picks the mode itself: 'none' for a plain list, 'items' for a selectable one (a listbox) and 'composite' (a grid) for a selectable list whose items have actions, which remounts the items when the first action appears or the last one disappears. An explicit value pins the structure:

- 'none': a plain list; its items are no Tab stops (their actions stay in the Tab order). A selectable list always navigates its items: there 'none' is ignored, with a development warning.
- 'items': the items are one Tab stop (the first selected item, else the first item; in a list without selection the item that last had focus), moved with ArrowUp/ArrowDown (wrapping) and Home/End, with typeahead for more than 7 items. A plain list keeps role="list" and its items carry no aria-selected; their actions stay in the Tab order. A selectable list whose items have actions acts as 'composite', with a development warning.
- 'composite': a grid (role="grid", rows and gridcells) from the first render, so the items never remount when actions appear. One Tab stop; Up/Down move between the rows and Right/Left (mirrored in right-to-left layouts) into and out of their actions, which leave the Tab order. The rows of a list without selection carry no aria-selected.

The resolved mode is rendered as data-navigation-mode. Changing it while mounted can switch between ul/li and div elements, which remounts the items (see List). A windowed list (virtualWindow) never switches for its items' actions: unset or 'items', a selectable one is a listbox; only 'composite' makes it a grid. In a windowed list the keys move by index over the whole list, PageUp/PageDown included (see virtualWindow).

checkmarkbooleanNofalse

Draws a check mark at the start of every item of a selectable list, shown while the item is selected (decorative: aria-selected carries the state). An item's own checkmark replaces or hides it. Renders data-checkmark on the list while it draws them.

refReact.Ref<HTMLUListElement | HTMLDivElement>No

Ref to the root element: a <ul>, or a <div role="grid"> for a selectable list whose items have actions and for navigationMode="composite".

Any other prop is passed to the element it renders (HTMLUListElement).

Parts

  • List.Item

Stable class names

PartClass
rootwave-list
spacerwave-list__spacer