---
title: Table
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, TokensTable, PropsTable } from '../../src/components'
import { Table, TableBody, TableCell, TableHeader, TableRow } from '@telus-uds/components-web'
import { Table as WebDocs } from 'docs/@telus-uds/components-web'
import AvailableOnWebOnly from '../../partials/_platform-considerations-web-only.mdx'

# Table

<LibraryInfo
  packageType="Web Component"
  figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2F4zJn2Qn6uXOqPP1GVDipy6%2F%25F0%259F%258D%2580-Allium-Components%3Fnode-id%3D8090%253A147592"
/>

```jsx live
<Table>
  <TableHeader>
    <TableCell />
    <TableCell>Peace of Mind</TableCell>
    <TableCell>Peace of Mind Connect</TableCell>
    <TableCell>Simple Share</TableCell>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell type="rowHeading">Data</TableCell>
      <TableCell>30GB</TableCell>
      <TableCell>15GB</TableCell>
      <TableCell>20GB</TableCell>
    </TableRow>
    <TableRow>
      <TableCell type="rowHeading">Network</TableCell>
      <TableCell>5G</TableCell>
      <TableCell>5G</TableCell>
      <TableCell>5G</TableCell>
    </TableRow>
    <TableRow>
      <TableCell type="rowHeading">Price</TableCell>
      <TableCell>$80/mo.</TableCell>
      <TableCell>$90/mo.</TableCell>
      <TableCell>$90/mo.</TableCell>
    </TableRow>
  </TableBody>
</Table>
```

## Introduction

Use `Table` to display tabular data.

- Available in 2 cell spacings (default, compact)
- Available in 2 text styles (medium, small)
- When `Table` exceeds viewport, the first column becomes sticky, enabling horizontal scrolling
- Right-align prices and numbers that display decimal points (`align` prop)

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

:::info
Table sub-components can also be used with dot notation. E.g. `<Table.Row />`, `<Table.Header />`, `<Table.Cell />`, `<Table.SubHeading />`, `<Table.Body />`, etc.
This is useful when you want to import the Table component without importing the subcomponents separately,
:::

- Use `TableHeader` and `TableBody` as direct children of `Table`
- Use `TableSubHeading` to render an intermediate data heading row
- Use `TableRow` and `TableCell` to build up the tabular data
- Use `Cell`'s `type` prop to visually mark it as a row heading (`variant={{ type: "rowHeading" }}`)
- Use `Cell`'s `align` prop to change its content horizontal alignment

### Accessibility

The `Table` component uses the native html table syntax, making it accessible for screen readers by design.

If the table's content is wider than the container's width, the table becomes scrollable and the first column
becomes sticky.

```jsx live
<Table spacing="compact" text="small">
  <TableHeader>
    <TableCell />
    <TableCell>Header 1</TableCell>
    <TableCell>Header 2</TableCell>
    <TableCell>Header 3</TableCell>
    <TableCell>Header 4</TableCell>
    <TableCell>Header 5</TableCell>
    <TableCell>Header 6</TableCell>
    <TableCell>Header 7</TableCell>
    <TableCell>Header 8</TableCell>
    <TableCell>Header 9</TableCell>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell type="rowHeading">Sticky first column</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
      <TableCell>Table data</TableCell>
    </TableRow>
  </TableBody>
</Table>
```

### Platform considerations

<AvailableOnWebOnly />

## Props

### Table

<PropsTable web={WebDocs} />

### TableHeader

<PropsTable web={WebDocs.Header} />

### TableBody

<PropsTable web={WebDocs.Body} />

### TableRow

<PropsTable web={WebDocs.Row} />

### TableSubHeading

<PropsTable web={WebDocs.SubHeading} />

### TableCell

<PropsTable web={WebDocs.Cell} />

## Tokens

<TokensTable web={WebDocs} component="Table" />

## Variants

### Compact spacing with small text

```jsx live
<Table spacing="compact" text="small">
  <TableHeader>
    <TableCell />
    <TableCell>Peace of Mind</TableCell>
    <TableCell>Peace of Mind Connect</TableCell>
    <TableCell>Simple Share</TableCell>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell type="rowHeading">Data</TableCell>
      <TableCell>30GB</TableCell>
      <TableCell>15GB</TableCell>
      <TableCell>20GB</TableCell>
    </TableRow>
  </TableBody>
</Table>
```

### Responsive table (fullWidth = false)

```jsx live
<Table fullWidth={false}>
  <TableHeader>
    <TableCell />
    <TableCell>Peace of Mind</TableCell>
    <TableCell>Peace of Mind Connect</TableCell>
    <TableCell>Simple Share</TableCell>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell type="rowHeading">Data</TableCell>
      <TableCell>30GB</TableCell>
      <TableCell>15GB</TableCell>
      <TableCell>20GB</TableCell>
    </TableRow>
  </TableBody>
</Table>
```

### Highlight row

Accessibility considerations for highlighting row:

- Table row hover may enhance accessibility and usability for users, especially in large tables
- Highlighting rows can helper users follow data from end to end
- It's important to ensure that the hover effect does not imply interactivity where there is none
- Limit dependence on this feature as hover effects are not accessible on devices without a mouse or pointer
- Consider other features such as zebra striping and clear, descriptive headers

```jsx live
<Table variant={{ highlight: 'row' }}>
  <TableHeader>
    <TableCell />
    <TableCell>Peace of Mind</TableCell>
    <TableCell>Peace of Mind Connect</TableCell>
    <TableCell>Simple Share</TableCell>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell type="rowHeading">Data</TableCell>
      <TableCell>30GB</TableCell>
      <TableCell>15GB</TableCell>
      <TableCell>20GB</TableCell>
    </TableRow>
    <TableRow>
      <TableCell type="rowHeading">Network</TableCell>
      <TableCell>5G</TableCell>
      <TableCell>5G</TableCell>
      <TableCell>5G</TableCell>
    </TableRow>
    <TableRow>
      <TableCell type="rowHeading">Price</TableCell>
      <TableCell>$80/mo.</TableCell>
      <TableCell>$90/mo.</TableCell>
      <TableCell>$90/mo.</TableCell>
    </TableRow>
  </TableBody>
</Table>
```

## Feedback

<Feedback component="Table" />
