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
| Name | Role | Location |
|---|---|---|
| Alice Johnson | Engineer | Seattle |
| Bob Smith | Designer | New York |
| Carol White | Manager | London |
export const Default: Story = {};Striped
| Name | Role | Location |
|---|---|---|
| Alice Johnson | Engineer | Seattle |
| Bob Smith | Designer | New York |
| Carol White | Manager | London |
export const Striped: Story = {
args: {
striped: true,
},
};With Caption And Scroll
| ID | Name | Role | Location | |
|---|---|---|---|---|
| 001 | Alice Johnson | alice@example.com | Engineer | Seattle |
| 002 | Bob Smith | bob@example.com | Designer | New York |
| 003 | Carol White | carol@example.com | Manager | London |
| 004 | David Brown | david@example.com | Analyst | Oslo |
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
| ID | Name | Role | Location | |
|---|---|---|---|---|
| 001 | Alice Johnson | alice@example.com | Engineer | Seattle |
| 002 | Bob Smith | bob@example.com | Designer | New York |
| 003 | Carol White | carol@example.com | Manager | London |
| 004 | David Brown | david@example.com | Analyst | Oslo |
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 Johnson | Engineer | Seattle |
| Bob Smith | Designer | New York |
| Carol White | Manager | London |
| David Brown | Analyst | Oslo |
export const SortableHeaders: Story = {
render: (args) => <SortableTable {...args} />,
};Custom Sort Icon
| Alice Johnson | Engineer | Seattle |
| Bob Smith | Designer | New York |
| Carol White | Manager | London |
| David Brown | Analyst | Oslo |
export const CustomSortIcon: Story = {
render: (args) => <SortableTable {...args} customGlyph />,
};Selection Cells
| Name | Role | |
|---|---|---|
| Alice Johnson | Engineer | |
| Bob Smith | Designer | |
| Carol White | Manager | |
| David Brown | Analyst |
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 contact | Name | |
|---|---|---|
| Alice Johnson | alice@example.com | |
| Bob Smith | bob@example.com | |
| Carol White | carol@example.com | |
| David Brown | david@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
| Member | Location |
|---|---|
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
| File | Owner |
|---|---|
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
| Name | Role |
|---|---|
| Alice Johnson | Engineer |
| Bob Smith | Designer |
| Carol White | Manager |
| David Brown | Analyst |
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
| Role | ||
|---|---|---|
Alice Johnson | Engineer | |
Bob Smith | Designer | |
Carol White | Manager |
| Role | ||
|---|---|---|
Alice Johnson | Engineer | |
Bob Smith | Designer | |
Carol White | Manager |
| 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
| Name | Role | Location |
|---|---|---|
| Alice Johnson | Engineer | Seattle |
| Bob Smith | Designer | New York |
| Carol White | Manager | London |
| David Brown | Analyst | Oslo |
| A neutral row | Fixed | Anywhere |
export const RowAppearance: Story = {
args: { 'aria-label': 'Team members, selectable rows' },
render: (args) => <SelectableRows {...args} />,
};Virtual Window
| Number | Name | Owner |
|---|---|---|
| 1 | File 0001 | Alice Johnson |
| 2 | File 0002 | Bob Smith |
| 3 | File 0003 | Carol White |
| 4 | File 0004 | David Brown |
| 5 | File 0005 | Alice Johnson |
| 6 | File 0006 | Bob Smith |
| 7 | File 0007 | Carol White |
| 8 | File 0008 | David Brown |
| 9 | File 0009 | Alice Johnson |
| 10 | File 0010 | Bob Smith |
| 11 | File 0011 | Carol White |
| 12 | File 0012 | David Brown |
| 13 | File 0013 | Alice Johnson |
| 14 | File 0014 | Bob Smith |
| 15 | File 0015 | Carol White |
| 16 | File 0016 | David Brown |
| 17 | File 0017 | Alice Johnson |
| 1,000 files | ||
export const VirtualWindow: Story = {
args: { striped: true, 'aria-label': 'A thousand files' },
render: (args) => <VirtualTable {...args} />,
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
size | 'medium' | 'small' | 'extra-small' | No | 'medium' | The density of the table: |
virtualWindow | VirtualWindow | No | Renders only the body rows in view, plus an overscan, of a table with many rows: pass the result of The table's scroll wrapper ( The table carries | |
striped | boolean | No | false | Whether to apply alternating row background colors (odd body rows). The stripe has zero specificity, so a row's own background class ( |
containerProps | Omit<React.ComponentPropsWithRef<'div'>, 'children'> | No | Props for the wrapper | |
children | React.ReactNode | Yes | Table caption, header, body and row elements. | |
ref | React.Ref<HTMLTableElement> | No | Ref to the |
Any other prop is passed to the element it renders (HTMLTableElement).
Parts
Table.HeaderTable.HeaderCellTable.BodyTable.RowTable.CellTable.SelectionCellTable.CellLayoutTable.CellActionsTable.ResizeHandle
Stable class names
| Part | Class |
|---|---|
root | wave-table |
container | wave-table__container |
spacer | wave-table__spacer |