Skip to content

Table

Table

A non-interactive data table with an optional striped body, in three densities (size). The table sits in a horizontally scrollable wrapper; while it scrolls, the wrapper is a focusable region (named by containerProps or the <caption>) so keyboard users can scroll it.

The table keeps no state: a sortable Table.HeaderCell reports its clicks, and a Table.SelectionCell (a native checkbox or radio) its changes, for your state to sort and select the rows. Table.CellLayout lays out a cell's media, text and description, and Table.CellActions shows a cell's actions while its row is hovered or holds focus, and a Table.Row fills itself with appearance (brand or neutral).

A table of many rows renders only the rows in view with a virtualWindow (from useVirtualWindow), a count on Table.Body and a function child that returns each row.

Sub-components are available as Table.Header, Table.HeaderCell, Table.Body, Table.Row, Table.Cell, Table.SelectionCell, Table.CellLayout, Table.CellActions and Table.ResizeHandle (the separator that resizes a column, for a header cell's aside) in client components, and as the flat exports TableHeader, TableHeaderCell, TableBody, TableRow, TableCell, TableSelectionCell, TableCellLayout, TableCellActions and TableResizeHandle (the form React Server Components can import).

Examples

Default

NameRoleLocation
Alice JohnsonEngineerSeattle
Bob SmithDesignerNew York
Carol WhiteManagerLondon
export const Default: Story = {};

Striped

NameRoleLocation
Alice JohnsonEngineerSeattle
Bob SmithDesignerNew York
Carol WhiteManagerLondon
export const Striped: Story = {
  args: {
    striped: true,
  },
};

With Caption And Scroll

Team directory
IDNameEmailRoleLocation
001Alice Johnsonalice@example.comEngineerSeattle
002Bob Smithbob@example.comDesignerNew York
003Carol Whitecarol@example.comManagerLondon
004David Browndavid@example.comAnalystOslo
export const WithCaptionAndScroll: Story = {
  args: {
    containerProps: { className: 'max-w-md' },
    className: 'min-w-[40rem]',
  },
  render: (args) => (
    <Table {...args}>
      <caption className="px-4 py-2 text-start text-wave-body-1 font-semibold">
        Team directory
      </caption>
      {header(['ID', 'Name', 'Email', 'Role', 'Location'])}
      <Table.Body>
        {members.map((member) => (
          <Table.Row key={member.id}>
            <Table.Cell>{member.id}</Table.Cell>
            <Table.Cell>{member.name}</Table.Cell>
            <Table.Cell>{member.email}</Table.Cell>
            <Table.Cell>{member.role}</Table.Cell>
            <Table.Cell>{member.location}</Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table>
  ),
};

Full Composition

IDNameEmailRoleLocation
001Alice Johnsonalice@example.comEngineerSeattle
002Bob Smithbob@example.comDesignerNew York
003Carol Whitecarol@example.comManagerLondon
004David Browndavid@example.comAnalystOslo
export const FullComposition: Story = {
  render: (args) => (
    <Table {...args}>
      {header(['ID', 'Name', 'Email', 'Role', 'Location'])}
      <Table.Body>
        {members.map((member) => (
          <Table.Row key={member.id}>
            <Table.Cell>{member.id}</Table.Cell>
            <Table.Cell>{member.name}</Table.Cell>
            <Table.Cell>{member.email}</Table.Cell>
            <Table.Cell>{member.role}</Table.Cell>
            <Table.Cell>{member.location}</Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table>
  ),
};

Sortable Headers

Alice JohnsonEngineerSeattle
Bob SmithDesignerNew York
Carol WhiteManagerLondon
David BrownAnalystOslo
export const SortableHeaders: Story = {
  render: (args) => <SortableTable {...args} />,
};

Custom Sort Icon

Alice JohnsonEngineerSeattle
Bob SmithDesignerNew York
Carol WhiteManagerLondon
David BrownAnalystOslo
export const CustomSortIcon: Story = {
  render: (args) => <SortableTable {...args} customGlyph />,
};

Selection Cells

NameRole
Alice JohnsonEngineer
Bob SmithDesigner
Carol WhiteManager
David BrownAnalyst
export const SelectionCells: Story = {
  args: { 'aria-label': 'Team members' },
  render: (args) => {
    const [selected, setSelected] = React.useState<readonly string[]>(['002']);
    const all = selected.length === members.length ? true : selected.length > 0 ? 'mixed' : false;
    return (
      <Table {...args}>
        <Table.Header>
          <Table.Row>
            <Table.SelectionCell
              aria-label="Select all members"
              checked={all}
              onCheckedChange={(checked) => setSelected(checked ? members.map((m) => m.id) : [])}
            />
            <Table.HeaderCell>Name</Table.HeaderCell>
            <Table.HeaderCell>Role</Table.HeaderCell>
          </Table.Row>
        </Table.Header>
        <Table.Body>
          {members.map((member) => (
            <Table.Row key={member.id}>
              <Table.SelectionCell
                subtle
                aria-label={`Select ${member.name}`}
                checked={selected.includes(member.id)}
                onCheckedChange={(checked) =>
                  setSelected((prev) =>
                    checked ? [...prev, member.id] : prev.filter((id) => id !== member.id),
                  )
                }
              />
              <Table.Cell>{member.name}</Table.Cell>
              <Table.Cell>{member.role}</Table.Cell>
            </Table.Row>
          ))}
        </Table.Body>
      </Table>
    );
  },
};

Radio Selection

Primary contactNameEmail
Alice Johnsonalice@example.com
Bob Smithbob@example.com
Carol Whitecarol@example.com
David Browndavid@example.com
export const RadioSelection: Story = {
  args: { 'aria-label': 'Primary contact' },
  render: (args) => (
    <Table {...args}>
      <Table.Header>
        <Table.Row>
          <Table.HeaderCell>
            <span className="sr-only">Primary contact</span>
          </Table.HeaderCell>
          <Table.HeaderCell>Name</Table.HeaderCell>
          <Table.HeaderCell>Email</Table.HeaderCell>
        </Table.Row>
      </Table.Header>
      <Table.Body>
        {members.map((member) => (
          <Table.Row key={member.id}>
            <Table.SelectionCell
              type="radio"
              name="primary-contact"
              value={member.id}
              defaultChecked={member.id === '001'}
              aria-label={`${member.name} is the primary contact`}
            />
            <Table.Cell>{member.name}</Table.Cell>
            <Table.Cell>{member.email}</Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table>
  ),
};

Cell Layouts

MemberLocation
Alice Johnsonalice@example.com
Seattle
Bob Smithbob@example.com
New York
Carol Whitecarol@example.com
London
David Browndavid@example.com
Oslo
export const CellLayouts: Story = {
  args: { 'aria-label': 'Team directory' },
  render: (args) => (
    <Table {...args}>
      {header(['Member', 'Location'])}
      <Table.Body>
        {members.map((member) => (
          <Table.Row key={member.id}>
            <Table.Cell>
              <Table.CellLayout
                appearance="primary"
                media={<Avatar name={member.name} decorative />}
                description={member.email}
              >
                {member.name}
              </Table.CellLayout>
            </Table.Cell>
            <Table.Cell>{member.location}</Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table>
  ),
};

Truncated Cell Layout

FileOwner
Quarterly financial results for the northern sales region.xlsxEdited yesterday by Bob Smith in the finance workspace
Alice Johnson
Roadmap.pptxEdited today
Carol White
export const TruncatedCellLayout: Story = {
  args: {
    'aria-label': 'Shared files',
    className: 'min-w-96 table-fixed',
    containerProps: { 'aria-label': 'Shared files' },
  },
  render: (args) => (
    <Table {...args}>
      <Table.Header>
        <tr>
          <Table.HeaderCell className="w-64">File</Table.HeaderCell>
          <Table.HeaderCell>Owner</Table.HeaderCell>
        </tr>
      </Table.Header>
      <Table.Body>
        {sharedFiles.map((file) => (
          <Table.Row key={file.name}>
            <Table.Cell>
              <Table.CellLayout truncate description={file.note} title={file.name}>
                {file.name}
              </Table.CellLayout>
            </Table.Cell>
            <Table.Cell>{file.owner}</Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table>
  ),
};

Cell Actions

NameRole
Alice JohnsonEngineer
Bob SmithDesigner
Carol WhiteManager
David BrownAnalyst
export const CellActions: Story = {
  args: { 'aria-label': 'Team members with actions' },
  render: (args) => (
    <Table {...args}>
      {header(['Name', 'Role'])}
      <Table.Body>
        {members.map((member, index) => (
          <Table.Row key={member.id}>
            <Table.Cell>{member.name}</Table.Cell>
            <Table.Cell>
              {member.role}
              <Table.CellActions visible={index === 0}>
                <Button size="small" appearance="subtle">
                  {`Edit ${member.name}`}
                </Button>
                <Button size="small" appearance="subtle">
                  {`Remove ${member.name}`}
                </Button>
              </Table.CellActions>
            </Table.Cell>
          </Table.Row>
        ))}
      </Table.Body>
    </Table>
  ),
};

Sizes

medium
Role
Alice Johnson
Engineer
Bob Smith
Designer
Carol White
Manager
small
Role
Alice Johnson
Engineer
Bob Smith
Designer
Carol White
Manager
extra-small
Role
Alice Johnson
Engineer
Bob Smith
Designer
Carol White
Manager
export const Sizes: Story = {
  render: (args) => (
    <div className="flex flex-col gap-6">
      {(['medium', 'small', 'extra-small'] as const).map((size) => (
        <Table key={size} {...args} size={size} aria-label={`Team members, ${size}`}>
          <caption className="px-4 py-2 text-start text-wave-body-1 font-semibold">{size}</caption>
          <Table.Header>
            <tr>
              <Table.SelectionCell aria-label={`Select all, ${size}`} />
              <Table.HeaderCell sortable sortDirection="ascending">
                Name
              </Table.HeaderCell>
              <Table.HeaderCell>Role</Table.HeaderCell>
            </tr>
          </Table.Header>
          <Table.Body>
            {members.slice(0, 3).map((member) => (
              <Table.Row key={member.id}>
                <Table.SelectionCell aria-label={`Select ${member.name}, ${size}`} />
                <Table.Cell>
                  <Table.CellLayout media={<Avatar name={member.name} />}>
                    {member.name}
                  </Table.CellLayout>
                </Table.Cell>
                <Table.Cell>{member.role}</Table.Cell>
              </Table.Row>
            ))}
          </Table.Body>
        </Table>
      ))}
    </div>
  ),
};

Row Appearance

NameRoleLocation
Alice JohnsonEngineerSeattle
Bob SmithDesignerNew York
Carol WhiteManagerLondon
David BrownAnalystOslo
A neutral rowFixedAnywhere
export const RowAppearance: Story = {
  args: { 'aria-label': 'Team members, selectable rows' },
  render: (args) => <SelectableRows {...args} />,
};

Virtual Window

A thousand files
NumberNameOwner
1File 0001Alice Johnson
2File 0002Bob Smith
3File 0003Carol White
4File 0004David Brown
5File 0005Alice Johnson
6File 0006Bob Smith
7File 0007Carol White
8File 0008David Brown
9File 0009Alice Johnson
10File 0010Bob Smith
11File 0011Carol White
12File 0012David Brown
13File 0013Alice Johnson
14File 0014Bob Smith
15File 0015Carol White
16File 0016David Brown
17File 0017Alice Johnson
1,000 files
export const VirtualWindow: Story = {
  args: { striped: true, 'aria-label': 'A thousand files' },
  render: (args) => <VirtualTable {...args} />,
};

Props

NameTypeRequiredDefaultDescription
size'medium' | 'small' | 'extra-small'No'medium'

The density of the table: 'medium' (the default; a one-line row is 44px tall), 'small' (34px) or 'extra-small' (24px, with the caption type size in the cells). It sets the padding of the cells, the header cells, the sort buttons and the selection cells, and the box of the media of a Table.CellLayout (an Avatar 32, 24 or 20px). A class of your own on a part still wins. Rendered as data-size on the table. Fluent's size.

virtualWindowVirtualWindowNo

Renders only the body rows in view, plus an overscan, of a table with many rows: pass the result of useVirtualWindow({ itemSize }) (or an object of your own that implements VirtualWindow) and give Table.Body the number of rows as count and a function child that returns the row at an index (<Table.Body count={n}>{(index) => <Table.Row>…</Table.Row>}). The rows that are not rendered are replaced by spacer rows (aria-hidden, data-virtual-spacer) of their height. Fluent has no counterpart in its Table.

The table's scroll wrapper (containerProps) becomes the window's scroller, so give it a bounded height or maximum height (a class or a style in containerProps): without one the window measures the whole list and renders every row (a development warning says so). The wrapper is then always a keyboard-focusable role="region" and needs a name (a <caption> or containerProps['aria-label']). Every body row has the window's itemSize as its height (the table sets it on each row, drops the vertical padding of its cells and keeps their text on one line, so a cell's content must fit in it), and the columns are laid out with a fixed table layout: give the columns their widths (a width on the header cells or a <colgroup>), as they would otherwise be as wide as the first row makes them. The header stays at the top of the scroller: pass its height as scrollPaddingStart to useVirtualWindow. A row that holds focus stays rendered when it is scrolled away.

The table carries aria-rowcount (the header rows, count and the rows of a <tfoot>), every row aria-rowindex (1-based, header rows first) and every body row data-row-index (its 0-based index); striped follows the row's index. A table without a body that has count and a function child ignores the window, with a development warning.

stripedbooleanNofalse

Whether to apply alternating row background colors (odd body rows). The stripe has zero specificity, so a row's own background class (<Table.Row className="bg-selected">) and its hover color win over it.

containerPropsOmit<React.ComponentPropsWithRef<'div'>, 'children'>No

Props for the wrapper <div> around the <table>: a horizontally scrollable container (overflow-x-auto). Use it for its className, style, ref or aria-label. While the table scrolls horizontally, the wrapper is a keyboard-focusable role="region" named by containerProps['aria-label']/['aria-labelledby'], else by the table's <caption>. While it does not scroll, the wrapper has no role and its aria-label/aria-labelledby are left off, unless you also pass a role in containerProps (then they are always applied).

childrenReact.ReactNodeYes

Table caption, header, body and row elements.

refReact.Ref<HTMLTableElement>No

Ref to the <table> element.

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

Parts

  • Table.Header
  • Table.HeaderCell
  • Table.Body
  • Table.Row
  • Table.Cell
  • Table.SelectionCell
  • Table.CellLayout
  • Table.CellActions
  • Table.ResizeHandle

Stable class names

PartClass
rootwave-table
containerwave-table__container
spacerwave-table__spacer