Components / Table
Table
A native, monospaced table for structured data. Compose a caption, column and row headers, body rows and a footer without replacing browser table semantics.
Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.
Usage playground
Author a useful caption, try long or empty data, and include a footer total. On narrow screens, Tab to the named scroll region and use arrow keys to read all columns. These controls are examples, not Table props. Reset restores recent invoices and the footer.
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV001 | Paid | Credit card | $250.00 |
| INV002 | Pending | Bank transfer | $150.00 |
| INV003 | Unpaid | PayPal | $350.00 |
| Total | $750.00 | ||
import { Table, TableBody, TableCaption, TableCell, TableContainer, TableFooter, TableHead, TableHeader, TableRow } from "@/components/ui/yads-table";
const rows = [
{
"invoice": "INV001",
"status": "Paid",
Installation
pnpm dlx [email protected] add biehlio/yet-another-design-system/table#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40This revision-pinned command installs yads-table, its scoped stylesheet and JetBrains Mono. Import { Table, TableContainer, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption } from @/components/ui/yads-table (adjust your alias). No Tailwind, reset, global CSS, provider or other YADS primitive is required. Light is the default; the nearest explicit .light or .dark boundary selects scoped colors.
Copy sample copies a complete React module, including data, native composition, layout and recipe CSS, even when collapsed. All samples need only this registry item. Table has no implicit wrapper; TableContainer is a separate named, keyboard-focusable scroll region. Give it aria-label or aria-labelledby. Playground controls are documentation controls, not additional Table props.
Grouped headers and spans
Use native colSpan and rowSpan. Match a colgroup header to actual colgroup elements; a rowgroup header belongs in its own tbody. Supply scope explicitly: col, row, colgroup or rowgroup. For more complex associations, author unique header ids and cell headers attributes.
| Region | Product | Revenue | |
|---|---|---|---|
| Q1 | Q2 | ||
| North | Hardware | $120 | $140 |
| Software | $80 | $90 | |
import { Table, TableBody, TableCaption, TableCell, TableContainer, TableFooter, TableHead, TableHeader, TableRow } from "@/components/ui/yads-table";
export default function GroupedTable() {
return <TableContainer aria-label="Quarterly revenue scroll area">
<Table style={{ minWidth: '28rem' }}>
<TableCaption>North region revenue, in dollars.</TableCaption>
Native props, refs and links
The ref is the actual table, not the scroll wrapper. Native attributes and typed events pass through. Focus this explicit tabIndex=-1 table programmatically; otherwise tables and cells are not Tab stops. Tab reaches the separate scroll region and real links, not a simulated grid. Arrow keys are not intercepted.
| Project | Action |
|---|---|
| Atlas | Review Atlas |
Atlas review destination.
'use client';
import { useRef, useState } from 'react';
import { Table, TableBody, TableCaption, TableCell, TableContainer, TableFooter, TableHead, TableHeader, TableRow } from "@/components/ui/yads-table";
export default function NativeTable() {
className customization
Ordinary CSS can make a compact table without changing associations, theme colors or focus outlines. Put table sizing on Table and scroll sizing on TableContainer. Long text wraps by default; an authored minWidth can retain readable columns and scroll within the container.
| Build | Result |
|---|---|
| #63 | Passed |
import { Table, TableBody, TableCaption, TableCell, TableContainer, TableFooter, TableHead, TableHeader, TableRow } from "@/components/ui/yads-table";
export default function CompactTable() {
return <>
<style>{".compactTable.compactTable th, .compactTable.compactTable td { padding: .5rem; border-bottom-style: dashed; }"}</style>
<TableContainer aria-label="Build table scroll area"><Table className="compactTable">
Accessibility
- Keep native structure. Use a meaningful caption, thead/tbody/tfoot groups, tr rows, th headers and td cells. Supply scope="col" or "row" for simple tables; use matching groups or explicit id/headers associations for complex tables. TableHead does not infer scope. Do not replace these with divs or role=grid.
- Contain horizontal overflow. TableContainer requires an authored accessible name and supplies role=region and tabIndex=0. Use a distinct, useful name such as Invoice table scroll area. Tab focuses the region; native arrow keys scroll overflowing content. Its focus ring and padding retain visible table/link outlines. Do not clip the region or remove its outline. It remains a Tab stop even when data fits; omit the optional container only when your own accessible overflow handling is adequate.
- No grid keyboard model. Tables, rows and cells are not automatically focusable. Links and buttons keep native Tab/Shift+Tab and Enter/Space behavior. Do not make a row clickable instead of giving its action a real link or button. Screen readers use their own native table navigation.
- Content stays readable. Long text wraps, including unbroken strings. Use minWidth on Table if columns need more room; the wrapper, not the page, scrolls. Author empty rows with a full-width colSpan and useful text. Totals, number formatting, empty messages and loading feedback belong to your application.
Light is the standalone default. The nearest explicit .light, .dark or data-theme="light|dark" boundary selects colors, including nested, self and live changes. No provider or system-preference detection is included. CSS @scope support is required for dark themes (Chrome/Edge 118+, Safari 17.4+, Firefox 146+); older browsers retain light styling. Forced colors retain system borders and focus outlines.
API reference
Import the named parts from @/components/ui/yads-table. Each part exports a matching Props type, such as TableProps or TableHeadProps. Native React attributes/events and actual element refs are forwarded unchanged, along with className, style, children, data-* and aria-*. No component adds a generated id, association, value, role or tabIndex except TableContainer’s default region and Tab stop. Native props can override those defaults; keep an accessible scroll region when doing so.
Focus this region and scroll horizontally to read all columns on narrow screens.
| Export | Element | Ref element | React props | Behavior / defaults |
|---|---|---|---|---|
Table | table | HTMLTableElement | TableHTMLAttributes | No wrapper; width 100%, wrapping text, separate borders. |
TableContainer | div | HTMLDivElement | HTMLAttributes + accessible name | Separate overflow:auto region, tabIndex=0. aria-label or aria-labelledby required. |
TableHeader | thead | HTMLTableSectionElement | HTMLAttributes | Column header group. |
TableBody | tbody | HTMLTableSectionElement | HTMLAttributes | Body row group; multiple bodies are allowed. |
TableFooter | tfoot | HTMLTableSectionElement | HTMLAttributes | Summary row group, not pagination. |
TableRow | tr | HTMLTableRowElement | HTMLAttributes | Native row, no selection or click behavior added. |
TableHead | th | HTMLTableCellElement | ThHTMLAttributes | Author scope, colSpan, rowSpan, id and headers as appropriate. No default scope. |
TableCell | td | HTMLTableCellElement | TdHTMLAttributes | Native data cell; colSpan, rowSpan and headers pass through. |
TableCaption | caption | HTMLTableCaptionElement | HTMLAttributes | Native accessible table name, visually below the table by default. |
Table versus container
Table forwards React.TableHTMLAttributes<HTMLTableElement>, including native table events. Its ref is always HTMLTableElement. TableContainer forwards div attributes/events and an HTMLDivElement ref; TypeScript requires an aria-label or aria-labelledby string, but cannot check that it is nonempty or points to an existing element. Put scroll listeners, the region name, and scroll sizing on the container. Put the caption, table name, native table attributes and column sizing on the table. No container is implicitly inserted by Table.
Native header and cell attributes
scope on TableHead is authored as col, row, colgroup or rowgroup; it is unset by default. colSpan and rowSpan on TableHead/TableCell are native numbers, normally 1 when omitted; native rowSpan=0 spans the remaining rows in that row group. headers is a space-separated string of header ids, not an automatic association. Native id, title, data-*, aria-*, className and style are unset unless supplied. Keep valid native nesting and associations; the component does not repair invalid markup.
Limits
No TanStack, sorting, filtering, pagination, row selection, virtualization, sticky headers, resizing, density variants or data engine is included. Compose native colgroup/col elements directly when needed. Table does not calculate totals, validate structure, invent header scopes, format values or announce data changes. No other YADS primitive, Tailwind, reset, global CSS variables or theme provider is required.