Table
Tables are an efficient way of displaying sets of repeating data with the same structure.
Anatomy - Tables
- Column Header: Includes column labels and extra functionality such as sort and filter.
- Cell: Supported Table widgets display here.
Usage Guidance
Data Tables are intended to display data that can be easily scanned and compared.
- Conceptually, each row in a Table represents an item, and each cell of that row is an attribute of that item.
- This means that all the cells in a particular column will be the same data type such as dates, numerals, text, etc.
- Ideally, there should be one value per cell. Field sets are discouraged.
- Nested Tables are highly discouraged.
When to Use
Use tables to allow users to:
- Easily scan and compare data
- View and edit data
- Manipulate and navigate through a large amount of data
- Preview data
When to Use Something Else
Consider another component when:
- You only have a small data set.
- A more detailed amount of information needs to be displayed by default.
- There is more than one piece of information within a cell.
Examples
Basic Example
Table includes a container Table
component and a TableRow
component. Table
is a simple wrapper
of the <table>
element with Canvas styles. TableRow
wraps <tr>
and supports additional props
to customize the style of the row.
Use Table
and TableRow
in conjunction with the standard <thead>
and <tbody>
elements to
create your Table.
ID | Name | Position | Location |
---|---|---|---|
1 | Aidan Brown | Product Manager | San Francisco, CA |
2 | Betty Chen | Product Designer | San Francisco, CA |
3 | Helen Gonzalez | Application Developer | Portland, OR |
4 | Timothy May | VP, Product Development | San Francisco, CA |
5 | John Hours | Product Manager | New York, New York |
Component API
Table
Table
is a simple wrapper of the <table>
element with Canvas styles. Use it as you would a
standard <table>
element.
<Table><thead><TableRow header={true}><th>ID</th><th>Name</th>...</TableRow></thead><tbody><TableRow><td>1</td><td>Aidan Brown</td>...</TableRow>...</tbody></Table>
Props
Table
does not have any documented props. Undocumented props are spread to its underlying
<table>
element.
TableRow
TableRow
wraps <tr>
and supports additional props to customize the style of the row. Use it as
you would a standard <tr>
element.
Set the header
prop of the TableRow
to designate whether or not it contains header elements.
ID | Name | Position | Location |
---|---|---|---|
1 | Aidan Brown | Product Manager | San Francisco, CA |
Set the state
prop of the TableRow
to display it using one of several different visual states.
state
accepts the following values:
TableRow.State.Selected
TableRow.State.Alert
TableRow.State.InputAlert
TableRow.State.Error
TableRow.State.InputError
State | Purpose |
---|---|
TableRow.State.Alert | When there is an issue with the entire row as a whole. |
TableRow.State.InputAlert | When there are issues with one or more (but not all) cells in the row. |
TableRow.State.Error | When there is an error with the entire row as a whole. |
TableRow.State.InputError | When there are errors with one or more (but not all) cells in the row. |
TableRow.State.Selected | Indicates the selected row to the user. |
ID | Name | Position | Location |
---|---|---|---|
1 | Aidan Brown | Product Manager | San Francisco, CA |
2 | Betty Chen | Product Designer | San Francisco, CA |
3 | Helen Gonzalez | Application Developer | Portland, OR |
4 | Timothy May | VP, Product Development | San Francisco, CA |
5 | John Hours | Product Manager | New York, New York |
6 | Leslie Lang | Software Architect | New York, New York |
InputAlert
and InputError
are identical to the Alert
and Error
states, respectively, except
they lack a darkened border around the row.
TableRow
Props
Props extend from tr. Changing the as
prop will change the element interface.
Name | Type | Description | Default |
---|---|---|---|
state |
| The state of the TableRow. Accepts | |
header | boolean | If true, render the TableRow with header elements. | false |
as |
| ||
children | React.ReactNode | ||
as | React.ElementType | Optional override of the default element used by the component. Any valid tag or Component. If you provided a Component, this component should forward the ref using Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care. | tr |
ref | React.Ref | Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If |
TableRow.State
Name | Type | Description | Default |
---|---|---|---|
Error | 0 | ||
Alert | 1 | ||
InputError | 2 | ||
InputAlert | 3 | ||
Hover | 4 | ||
Selected | 5 |
Accessibility Guidelines
- No column header cells should be blank.
- When possible, each cell should only have one piece of data.
- Avoid placing multiple inactive controls into a single cell.
Content Guidelines
- When writing titles, column headers, and other text for Tables, refer to the Tables section of the Content Style Guide.
Mobile
Platform | Availability |
---|---|
iOS | Yes |
Android | Yes |
Guidelines
Due to screen size limitations, the display of Tables on mobile is different from the desktop display. Rather than displaying inline on the page, there is a tile preview which the user can tap to display a full-page view-only Table. To edit the data in this Table, the user taps the row they wish to edit and an editable form of that row is shown.
Please note: Tables 2.0 is not currently available for Mobile applications.
Can't Find What You Need?
Check out our FAQ section which may help you find the information you're looking for.
FAQ Section