Raft 设计系统

组件 · 数据展示

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

SituationUse
Values compared down columns: usage per month, invoices, access per resourceTable
The properties of one item: Status, Assignee, Created byDescriptionList
A list of people, agents, channels or settingsListRow
A table in Markdown that someone wrote in a messageThe MarkdownTable parts, in the code block's container (Built from existing parts)

Anatomy

  • Table: the table element. It fills its container's width and has no outer border. Required.
  • TableCaption: the table's name, shown under the table in text-caption and foreground-hint, or hidden with sr-only. Required unless the table has an aria-label.
  • TableColgroup and TableColumn: optional column widths.
  • TableHeader, with one TableRow of TableHead cells: the column headings. Required.
  • TableBody, with a TableRow of TableCells 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

StateLook
Hover, pressThe 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-fixed class to Table and set the widths with TableColgroup and TableColumn.
  • 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).
  • TableCell doesn't set numbers in Space Mono or align them: set both on the cell and on its TableHead, 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, th and td elements, so screen readers can move by row and column.
  • TableHead sets scope="col". Row headings (scope="row") work but have no style of their own.
  • Name every table with a TableCaption, visible or sr-only. Use aria-label on Table only 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类型默认值
renderAllows 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: TableBody rows, an InboxItem's pressed toggle action, the Activity inbox sort button and a FileRow (when its FileRowOpen is hovered) now only show their hover on devices that can hover. With a mouse they look and behave as before.