Components
Table
Rows and columns in a real semantic table, the readable twin a chart ships with, with a required caption, right-aligned numeric columns and its own scroll.
Usage
pnpm dlx shadcn@latest add @opsinjs/table
The @opsinjs namespace is declared in your components.json. Everything it installs is code you then own. There is no runtime package to keep in step.
import { Table } from "@/components/ui/table"<Table
caption="Example figures by period, and not a real record"
columns={[
{ key: "period", header: "Period" },
{ key: "count", header: "Count", numeric: true },
]}
rows={[
{ period: "Period one", count: "12" },
{ period: "Period two", count: "1,000" },
]}
/>Examples
table · base base · style base-lyraOpen under the product themeThe readable twin of a chart
The chart draws the shape; the table carries the figures. captionHidden hides
the caption the heading above already supplies.
table-a-chart-twin · base base · style base-lyraOpen under the product themeimport { Table } from "@/components/ui/table"
export default function TableAChartTwin() {
return (
<figure className="m-0 flex w-full max-w-md flex-col gap-opsin-2">
<figcaption className="text-opsin-subheadline [color:var(--foreground)]">
Example series, and not a real record
</figcaption>
{/* The chart sits here in a real surface; this table is its readable twin. */}
<Table
captionHidden
caption="Example series by period, the readable twin of the chart above, showing an example count for each period"
columns={[
{ key: "period", header: "Period" },
{ key: "count", header: "Count", numeric: true },
]}
rows={[
{ period: "Period one", count: "12" },
{ period: "Period two", count: "1,000" },
{ period: "Period three", count: "8" },
]}
/>
</figure>
)
}Numeric columns line up on their digits
numeric right-aligns two columns in tabular figures while the first column
labels each row.
table-numeric-columns · base base · style base-lyraOpen under the product themeimport { Table } from "@/components/ui/table"
import { Value } from "@/components/ui/value"
export default function TableNumericColumns() {
return (
<Table
caption="Example readings by row, and not a real record of anyone's"
columns={[
{ key: "row", header: "Example row" },
{ key: "reading", header: "Reading", numeric: true },
{ key: "change", header: "Change", numeric: true },
]}
rows={[
{
row: "First example row",
reading: <Value value={1000.2} unit="kg" precision={1} />,
change: <Value value={7} unit={null} precision={0} />,
},
{
row: "Second example row",
reading: <Value value={903.4} unit="kg" precision={1} />,
change: <Value value={1024} unit={null} precision={0} />,
},
{
row: "Third example row",
reading: <Value value={888.0} unit="kg" precision={1} />,
change: <Value value={128} unit={null} precision={0} />,
},
]}
/>
)
}When to use it
Use it when
- The accessible twin of a chart: the same figures a screen reader user can read.
- A small set of rows and columns a reader compares directly.
- A comparison read down a column, where lining the digits up is the point.
Do not use it when
- One reading with a label, a time and a surface of its own.Use
metric-tileinstead. - A trend read as a shape rather than as figures.Use
trend-sparklineinstead. - The data has not arrived and you are holding the layout open.Use
skeletoninstead. - There are no rows, because the result is genuinely empty.Use
empty-stateinstead. - An interactive grid with sorting, selection and virtualised scrolling.Use
cardinstead.
Accessibility
The audit changed nothing and found no axe violation, target-size failure,
focus-visible gap or sideways page scroll at 320px. A real <caption> always renders,
headers carry scope="col", and the first body cell carries scope="row" when
rowHeader is on. The overflow-x-auto container is tabIndex=0, reachable and
scrollable by keyboard, and padding-based spacing with no fixed cell heights keeps
text-spacing overrides from clipping. There is no colour prop, no data-status, no
data-category and no transition.
Residual items.
- An empty
captionrenders an empty<caption>, warning only in development. - The scroll container has no
roleand no accessible name; addingrole="region"would require one, so it is left to the consuming page. - Contrast for the header ink, caption ink and hairlines has not been measured.
| Key | Action | Notes |
|---|---|---|
| Tab | Moves focus onto the scrollable table, then past it | Present even when the table fits. |
| Shift+Tab | Moves back out of the table | Cells are never focus stops. |
| Left, Right | Scroll the table sideways when the container has focus | Native to a focusable scroll region. |
| Space | Scrolls the page, as anywhere else | No control here captures it. |
Contrast: 36 measured token pairs, 15 below floor
| Pair | Theme | APCA Lc | WCAG 2.2 | Floor |
|---|---|---|---|---|
| body text on the page | light | 101.6 | 17.18:1 | Pass |
| body text on the page | dark | -100.5 | 18.00:1 | Pass |
| body text on a card | light | 104.7 | 17.96:1 | Pass |
| body text on a card | dark | -99.6 | 16.32:1 | Pass |
| body text on the muted ground | light | 98.1 | 16.32:1 | Pass |
| body text on the muted ground | dark | -97.5 | 13.77:1 | Pass |
| secondary text on the page | light | 83.9 | 7.42:1 | Pass |
| secondary text on the page | dark | -80.7 | 13.44:1 | Pass |
| secondary text on a card | light | 87.0 | 7.76:1 | Pass |
| secondary text on a card | dark | -79.8 | 12.19:1 | Pass |
| secondary text on the muted ground | light | 80.4 | 7.05:1 | Pass |
| secondary text on the muted ground | dark | -77.8 | 10.28:1 | Pass |
| a hairline boundary on the page | light | 19.3 | 1.41:1 | Below floor |
| a hairline boundary on the page | dark | -8.2 | 1.90:1 | Below floor |
| a hairline boundary on a card | light | 22.4 | 1.47:1 | Below floor |
| a hairline boundary on a card | dark | -7.3 | 1.72:1 | Below floor |
| a hairline boundary on the muted ground | light | 15.8 | 1.34:1 | Below floor |
| a hairline boundary on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on the page | light | 69.8 | 4.52:1 | Pass |
| a placeholder boundary on the page | dark | -51.0 | 7.62:1 | Pass |
| a placeholder boundary on a card | light | 72.8 | 4.72:1 | Pass |
| a placeholder boundary on a card | dark | -50.1 | 6.91:1 | Pass |
| a placeholder boundary on the muted ground | light | 66.2 | 4.29:1 | Pass |
| a placeholder boundary on the muted ground | dark | -48.1 | 5.83:1 | Pass |
| a placeholder fill on the page | light | 8.3 | 1.18:1 | Below floor |
| a placeholder fill on the page | dark | -8.2 | 1.90:1 | Below floor |
| a placeholder fill on a card | light | 11.4 | 1.23:1 | Below floor |
| a placeholder fill on a card | dark | -7.3 | 1.72:1 | Below floor |
| a placeholder fill on the muted ground | light | 0.0 | 1.12:1 | Below floor |
| a placeholder fill on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on its own fill | light | 58.9 | 3.84:1 | Pass |
| a placeholder boundary on its own fill | dark | -41.5 | 4.01:1 | Below floor |
| the card hairline on the page | light | 69.8 | 4.52:1 | Pass |
| the card hairline on the page | dark | -28.7 | 4.19:1 | Below floor |
| the card hairline on a card | light | 72.8 | 4.72:1 | Pass |
| the card hairline on a card | dark | -27.9 | 3.80:1 | Below floor |
These are the measured token pairs this component draws colour from, not a measurement of the component itself.
Props interface
Prop
Type
Generated from TableProps in registry/bases/base/table.tsx.
caption is a required string. rowHeader defaults to true, so the first
cell of each row is a th. There is no onSort, no selectedRows and no
virtualized.
Data attributes
| Attribute | Condition | Value |
|---|---|---|
| data-slot | On the container, the table and every inner part, always | table-container, table, table-caption, table-header, table-head, table-body, table-row, table-cell |
| data-opsinjs-value | On a td in a numeric column | The empty string, deliberately: a tabular-figures hook, not a magnitude |