suiss/ui · Component
Table
Styled native table elements for displaying rows of structured data.
Table is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Table renders a native table inside a container that scrolls horizontally when the table is too wide. Build it from TableHeader, TableBody and TableFooter, each holding TableRow elements with TableHead or TableCell cells. TableCaption adds a caption below the table.
The parts add spacing, hairline row dividers, hover and selection backgrounds, and tabular numbers in cells. They don't add sorting, pagination or selection logic; handle those in your own code.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
-
Add the
cnhelper. -
Copy the source into
components/ui/table.tsx:
- Update the import paths to match your project.
Usage
Every part passes its props to the native element, so use standard attributes such as colSpan. Align numeric columns with text-end on both the TableHead and its cells. To highlight a row, set data-selected on TableRow.
Examples
Selected row
Highlights one row with the data-selected attribute.
API Reference
Table
The table element, wrapped in a horizontally scrolling container.
Also accepts the props of React.ComponentProps<"table">.
TableHeader
The thead section for column headings.
Also accepts the props of React.ComponentProps<"thead">.
TableBody
The tbody section for data rows.
Also accepts the props of React.ComponentProps<"tbody">.
TableFooter
The tfoot section, shaded and bold, for totals or summaries.
Also accepts the props of React.ComponentProps<"tfoot">.
TableRow
A tr row with a bottom divider and hover background.
Also accepts the props of React.ComponentProps<"tr">.
TableHead
A th column heading in small, secondary text.
Also accepts the props of React.ComponentProps<"th">.
TableCell
A td data cell with tabular numbers.
Also accepts the props of React.ComponentProps<"td">.
TableCaption
A caption shown below the table that also names it.
Also accepts the props of React.ComponentProps<"caption">.
Accessibility
- The parts render native table elements, so rows, column headers and cells keep their built-in roles.
TableCaptiongives the table its accessible name.
Notes
data-selectedis matched by presence, so leave the attribute off unselected rows rather than setting it tofalse.- A
TableRowthat contains an element witharia-expandedalso gets the selected background. - Header and data cells that contain a
role="checkbox"drop their end padding. - Parts carry
data-slotattributes such astable-container,table,table-rowandtable-cell. - Hover and selection use the
accentcolor; the footer uses a tintedmuted.