组件 · 数据展示
Table
Rows and columns of data on native table elements, for the few places that need columns, such as usage, billing and permissions.
也叫 Data table
import { Table } from "@botiverse/raft-ui";A table lays out data in rows and columns, with a header row and a hairline between rows. Use it only when the data has to be compared down columns, such as usage, billing or the permissions of an app. Everything else reads better as a DescriptionList or as ListRow rows (Built from existing parts).
When to use
| Situation | Use |
|---|---|
| Values compared down columns: usage per month, invoices, access per resource | Table |
| The properties of one item: Status, Assignee, Created by | DescriptionList |
| A list of people, agents, channels or settings | ListRow |
| A table in Markdown that someone wrote in a message | The MarkdownTable parts, in the code block's container (Built from existing parts) |
Anatomy
Table: thetableelement. It fills its container's width and has no outer border. Required.TableCaption: the table's name, shown under the table intext-captionandforeground-hint, or hidden withsr-only. Required unless the table has anaria-label.TableColgroupandTableColumn: optional column widths.TableHeader, with oneTableRowofTableHeadcells: the column headings. Required.TableBody, with aTableRowofTableCells per row. Required.
The header type, the lines between rows and how numbers are set are in Built from existing parts › Tables. Table draws the header and the lines; the last row has none under it.
States
| State | Look |
|---|---|
| Hover, press | The row lays fill-subtle over itself on hover, the subtle tier, and fill-medium on press; a selected row keeps info-soft (Hover and press) |
Menu open (data-popup-open on TableRow, or on a button in it) | fill-subtle, the same subtle tier as the hover, so the row the menu acts on stays marked; a selected row keeps info-soft (Hover and press) |
Selected (aria-selected or data-selected="true" on TableRow) | info-soft: a selected row is selected content |
Behavior
- Columns take the width of their content. When content would make them jump (a value that changes, rows that load in), add the
table-fixedclass toTableand set the widths withTableColgroupandTableColumn. - Text in a cell wraps at any character, so an ID or a name without spaces breaks inside its column instead of pushing the table past its container.
- Cells align their content to the top, so a row with a 2-line description keeps its other values on the first line.
Content
- Write column headings in sentence case: Resource, Access, Last run (Writing).
TableCelldoesn't set numbers in Space Mono or align them: set both on the cell and on itsTableHead, so the heading sits over its numbers.- Write a caption in sentence case that names what the rows are: Recent builds.
Accessibility
- The parts render native
table,caption,thead,tbody,tr,thandtdelements, so screen readers can move by row and column. TableHeadsetsscope="col". Row headings (scope="row") work but have no style of their own.- Name every table with a
TableCaption, visible orsr-only. Usearia-labelonTableonly when there can be no caption. - Give a control in a cell a name that includes its row: "Access for Messages".
Rules
- Keep the header row even when the design shows none: hide it with
sr-only. Without it, the columns lose their names. - Don't add vertical lines, an outer border or a header fill. A composite adds no new lines or colors (Built from existing parts).
API
Table, TableBody, TableCaption, TableCell, TableColgroup, TableColumn, TableHead, TableHeader, TableRow
Native `<table>` semantics with the kit's chrome: render real table/thead/tbody/tr/th/td elements (useRender passthrough), so `scope`, screen-reader navigation and keyboard behaviour stay intact. A caller that wants a visually header-less table keeps its `<TableHead>` and hides it with `sr-only`; omitting the header would drop the semantics.
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
相关组件
改动
- 0.9.5 · FixedOn a touch screen, a tap no longer leaves a hover highlight on:
TableBodyrows, anInboxItem's pressed toggle action, the Activity inbox sort button and aFileRow(when itsFileRowOpenis hovered) now only show their hover on devices that can hover. With a mouse they look and behave as before.