Table

Tables are an efficient way of displaying sets of repeating data with the same structure.

GitHubStorybook
yarn add @workday/canvas-kit-preview-react
Sources
GitHubStorybook
Install
yarn add @workday/canvas-kit-preview-react

Anatomy - Tables

Example of the anatomy of a Table.

  1. Table Header (Optional): May consist of a header, result count, optional subheading, or any custom configuration of text.
  2. Table Outline (Optional): A border is used by default, but may be omitted for a full page table or in cases where a table is the sole element on a page.
  3. Column Header: Include just column labels by default, but icon actions for actions such as sort and filter may be added. Note that this functionality will be a custom add for developers.
  4. Cell: May consist of text, icons, status indicators, buttons, data types, or other custom content. Text overflows by default, but teams may elect to apply truncation with a tooltip.

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.

Dos and Don'ts

Do

Right align numeric data in tables.

Do

Right align actions in tables.

Do

Allow cell text to wrap where possible, giving users access to the full contents of the cell by default.

Do

We recommend wrapping text where possible, but if needed, cell text may be truncated, showing full text in a tooltip on hover.

Examples

Basic Example

Users may not want to use a caption so they can import Heading or Text instead. This will give the user more flexibility around the customization of the title/heading of their table.

Pizza Toppings

ToppingsAmount
Pepperoni2.5 oz
Mozzarella5 oz
Basil10 Leaves

Example with Caption

Users are free to use a caption instead of a heading. A caption is not required but it is good for accessibility purposes.

Coffee Drinks and Sizes
DrinkSize
Espresso1 oz
Macchiato2 oz Espresso
Cortado2 oz Espresso, 1 oz Foamed Milk
Cappuccino2 oz Espresso, 2 oz Foamed Milk, 2 oz Steamed Milk

Fixed Column

Users may add styles to the Table.Header to render a fixed column. The example below assigns a width to the Table to guarantee the fixed column is triggered, but you are free to omit the width if you would only like the fixed column to be triggered if necessary.

Performance Car Specs

BrandModelYearPriceEngineTransmissionHorsepowerTorqueTires
Porsche992 911 GT32022Starts at $160,0004.0L Flat 6PDK or 7-Speed Manual502hp346 lb-ft3,164 lbs
BMWM5 Competition2018Starts at $105,000Twin-Turbo 4.4L V8Automatic627hp553 lb-ft4,345 lbs
AudiR82022Starts at $148,0005.2L V10Automatic562hp408 lb-ft3,594 lbs
LotusEmira2023Starts at $78,000Supercharged 3.5L V6Automatic or 6-Speed Manual400hp317 lb-ft3520 lbs
ToyotaSupra1998$40,000 - $80,0003.0L Inline 6Automatic or 6-Speed Manual320hp315 lb-ft3,599 lbs
NissanSkyline GT-R1994$45,000 - $90,0002.6L Twin-Turbo Inline 65-Speed Manual276hp260 lb-ft3,153 lbs

Component API

Table

Table is a simple styled compound component that renders a table element. It is used to present information in a two-dimensional table comprised of rows and columns of cells containing data.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Caption>Table Caption</Table.Caption>
<Table.Head>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Header>Table Header</Table.Header>
</Table.Row>
</Table.Head>
<Table.Body>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Header>Table Header</Table.Header>
</Table.Row>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Data Cell</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Data Cell</Table.Cell>
</Table.Row>
</Table.Body>
<Table.Footer>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Data Cell</Table.Cell>
</Table.Row>
</Table.Footer>
</Table>
);
}

Layout Component

Table supports all props from thelayout component.

Props

Props extend from table. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

table
refReact.Ref<R = table>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Table.Caption

Table.Caption renders a caption element.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Caption>Table Caption</Table.Caption>
<Table.Body>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Cell</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
);
}

Layout Component

Table.Caption supports all props from thelayout component.

Props

Props extend from caption. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

caption
refReact.Ref<R = caption>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Table.Head

Table.Head renders a thead element.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Head>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Cell</Table.Cell>
</Table.Row>
</Table.Head>
</Table>
);
}

Layout Component

Table.Head supports all props from thelayout component.

Props

Props extend from thead. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

thead
refReact.Ref<R = thead>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Table.Body

Table.Body renders a tbody element.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Body>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Cell</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
);
}

Layout Component

Table.Body supports all props from thelayout component.

Props

Props extend from tbody. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

tbody
refReact.Ref<R = tbody>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Table.Row

Table.Row renders a tr element.

Note: Table.Row is built on Grid. It will look for how many children are there and if those children are valid React Elements. This will adjust the amount of columns automatically using the gridTemplateColumns style prop and the width of the columns is also set using a minmax function in the gridTemplateColumns style prop. If a user would like to adjust this, it can be overwritten on Table.Row. See the example below for how to overwrite gridTemplateColumns.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Head>
<Table.Row gridTemplateColumns="repeat(4, minmax(100px, 1fr))">
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Cell</Table.Cell>
</Table.Row>
</Table.Head>
</Table>
);
}

Layout Component

Table.Row supports all props from thelayout component.

Props

Props extend from tr. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

tr
refReact.Ref<R = tr>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Table.Header

Table.Header renders a th element.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Head>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Cell</Table.Cell>
</Table.Row>
</Table.Head>
</Table>
);
}

Layout Component

Table.Header supports all props from thelayout component.

Props

Props extend from th. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

th
refReact.Ref<R = th>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Table.Cell

Table.Cell renders a td element.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Body>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Cell</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
);
}

Layout Component

Table.Cell supports all props from thelayout component.

Props

Props extend from td. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

td
refReact.Ref<R = td>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Table.Footer

Table.Footer renders a tfoot element.

import {Table} from '@workday/canvas-kit-preview-react/table';
export default function App() {
return (
<Table>
<Table.Footer>
<Table.Row>
<Table.Header>Table Header</Table.Header>
<Table.Cell>Table Cell</Table.Cell>
</Table.Row>
</Table.Footer>
</Table>
);
}

Layout Component

Table.Footer supports all props from thelayout component.

Props

Props extend from tfoot. Changing the as prop will change the element interface.

NameTypeDescriptionDefault
childrenReactNode
asReact.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 React.forwardRefand spread extra props to a root element.

Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care.

tfoot
refReact.Ref<R = tfoot>

Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If as is set to an element, it will be that element. If as is a component, the reference will be to that component (or element if the component uses React.forwardRef).

Accessibility Guidelines

  • Table Header should be an HTML heading element, with a configurable heading level, based on the page structure context.
  • No column header cells should be blank.
  • Column headers must use <th> elements with scope="col" attributes.
  • When possible, each cell should only have one piece of data.
  • Avoid placing multiple inactive controls into a single cell.
  • If using custom functionality in column headers, meet with a11y team to create an accessible experience. Custom functionality may include filtering, sorting, or row selection with checkboxes.

Content Guidelines

  • When writing titles, column headers, and other text for Tables, refer to the Tables section of the Content Style Guide.

Mobile

PlatformAvailability
iOSYes
AndroidYes

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