Content
Table
A table sets records that share the same fields in columns so people can read across and compare, such as the timeline's entries on the web.
In kanso-ui as Table
Web and native
Table in kanso-ui 0.59.0, for React.
import { Table } from '@kanso-labs/kanso-ui'A grid of rows and columns with optional sorting, selection, column resizing, a sticky header and a footer row.
Material Design has no current data table page, so the geometry follows the archived Material Design data tables page: a 56px header row in a medium weight, 52px body rows, 16px of padding on each side of a cell and an arrow beside the sorted column's name. Its colour roles and state layers are the current system's, the same hover, pressed and selected treatment a list row takes. It is built on React Aria's Table.
What you provide
- An accessible name:
aria-labeloraria-labelledby. Table.HeaderwithTable.Columnentries, one of them markedisRowHeaderso a screen reader can read a row by it.Table.BodywithTable.Rowentries, each holding oneTable.Cellper column.- An
idon every row and every column. They share one namespace, so keep the two sets apart (for example, prefix column ids withcol); a shared value drops every column. - A surface around it if it needs one, such as an outlined Card with no padding.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
caption | ReactNode | — | The table's title, drawn over it as Kanso's caption, in the voice face at 22/28, and the name a screen reader gives the table, unless an `aria-label` or `aria-labelledby` names it instead. With a caption, the caption and the table sit in one wrapper, and the call site's `ref` and a value `className` and `style` land on that wrapper. A function `className` or `style`, which reads the table's render state, stays on the table itself. |
className | TableProps$1['className'] | — | A function may compute the class from the table's render state. |
onResize | ResizableTableContainerProps['onResize'] | — | Called as a column is dragged, with every column's width. |
onResizeEnd | ResizableTableContainerProps['onResizeEnd'] | — | Called once a drag ends, with every column's width. |
resizable | boolean | — | Lets columns marked `resizable` be dragged, by putting the table in the container React Aria keeps the resize state on. A resizable table sizes to its columns rather than to its parent, and that container is what fills the width and scrolls instead. |
resizeLabel | string | — | What the resize handle is called, for a screen reader. React Aria composes it with the column's own name. Left out, React Aria names it in the reader's locale — "Resizer" in English. |
selectAllLabel | string | — | What the select-all checkbox is called, for a screen reader. Left out, React Aria names it in the reader's locale — "Select All" in English. |
selectLabel | string | — | What each row's selection checkbox is called, for a screen reader. The row's own text is what names the row; this names the box inside it. Left out, React Aria names it in the reader's locale — "Select" in English. |
stickyHeader | boolean | — | Holds the header row in place while the rows scroll under it. Needs the table inside something that scrolls; on a table that does not, it draws the same as without it. |
style | TableProps$1['style'] | — | A function may compute the style from the table's render state. |
Also takes the props of Omit<TableProps$1, 'className' | 'style'>.
Parts
Table.Header: the header row holding the columns, with a rule under it.Table.Column: one column; its children are its name.isRowHeadermarks the column a row is read by,allowsSortingmakes the header cell the control that sorts,selectiondraws the select-all checkbox, andresizabledraws a drag handle at its trailing edge (withdefaultWidth,minWidthandmaxWidth).align:'start' | 'end', default'start';endis for a column of numbers, setting the name against the end padding with the sort arrow before it.Table.Body: the rows.renderEmptyStateis what it shows when there are none.Table.Row: one row, with anid.onActionruns when it is pressed.Table.Cell: one cell.selectiondraws the row's checkbox in place of its content.align:'start' | 'end'— give it its column's value, since a cell does not follow the header on its own.Table.Footer: a row under the body for totals and the like, kept out of selection and keyboard navigation.Table.LoadMore: the row shown while more rows are fetched, placed insideTable.Bodyafter the rows. React Aria callsonLoadMorewhen it comes into view and draws it only whileisLoading.
Example
import { Table } from '@kanso-labs/kanso-ui'
<Table aria-label="Label" selectionMode="multiple">
<Table.Header>
<Table.Column id="colSelect" selection />
<Table.Column id="colName" isRowHeader>Label</Table.Column>
<Table.Column id="colValue">Value</Table.Column>
</Table.Header>
<Table.Body>
<Table.Row id="first">
<Table.Cell selection />
<Table.Cell>First item</Table.Cell>
<Table.Cell>01</Table.Cell>
</Table.Row>
</Table.Body>
</Table>The design’s classes
k-table, k-table-wrap, k-num, with k-mark, k-badge, k-badge--positive and k-badge--caution. Maps to Table in kanso-ui and react-native-kanso-ui.