Todae

Todae

Table

Table.Root is a native <table> styled from the table contract tokens. Build it from its parts: Table.Caption, Table.Head, Table.Body, Table.Foot, Table.Row, Table.HeaderCell and Table.Cell render <caption>, <thead>, <tbody>, <tfoot>, <tr>, <th> and <td>, so the table keeps the meaning the browser gives it. Numbers use tabular figures, so digits have equal width; give a numeric column text-align: end so its values line up on the right.

On this page
import { Table } from '@tounsoo/todae/table';

export default function TableOfInvoices() {
  return (
    <Table.Root>
      <Table.Caption>Invoices this quarter</Table.Caption>
      <Table.Head>
        <Table.Row>
          <Table.HeaderCell scope="col">Invoice</Table.HeaderCell>
          <Table.HeaderCell scope="col">Date</Table.HeaderCell>
          <Table.HeaderCell scope="col" style={{ textAlign: 'end' }}>
            Amount
          </Table.HeaderCell>
        </Table.Row>
      </Table.Head>
      <Table.Body>
        <Table.Row>
          <Table.HeaderCell scope="row">INV-1042</Table.HeaderCell>
          <Table.Cell>2026-07-03</Table.Cell>
          <Table.Cell style={{ textAlign: 'end' }}>$1,200.00</Table.Cell>
        </Table.Row>
        <Table.Row>
          <Table.HeaderCell scope="row">INV-1043</Table.HeaderCell>
          <Table.Cell>2026-08-01</Table.Cell>
          <Table.Cell style={{ textAlign: 'end' }}>$980.00</Table.Cell>
        </Table.Row>
        <Table.Row>
          <Table.HeaderCell scope="row">INV-1044</Table.HeaderCell>
          <Table.Cell>2026-09-02</Table.Cell>
          <Table.Cell style={{ textAlign: 'end' }}>$1,450.00</Table.Cell>
        </Table.Row>
      </Table.Body>
    </Table.Root>
  );
}
Invoices this quarter
InvoiceDateAmount
INV-10422026-07-03$1,200.00
INV-10432026-08-01$980.00
INV-10442026-09-02$1,450.00

Server Components can import it from @tounsoo/todae/table. Give every column header scope="col" and every row header scope="row". A Table.Caption names the table for screen readers. Restyle through table.border, table.rule.thickness, table.header.*, table.caption.fg and table.cell.padding.*; the padding follows density.

Sorting

Give a sortable column's Table.HeaderCell a sort of 'ascending', 'descending' or 'none', and put a Table.SortButton inside it with the column's label as its children. The cell takes data-sort, and aria-sort for the sorted column alone: 'none' leaves aria-sort off, so only data-sort marks the column as sortable. Todae does not sort the rows. Sort them in your own code, in memory or with a request, and set each cell's sort from onClick.

import { Table, type TableSort } from '@tounsoo/todae';
import { useState } from 'react';

const INVOICES = [
  { id: 'INV-1042', status: 'Paid', amount: 1200 },
  { id: 'INV-1043', status: 'Overdue', amount: 980 },
  { id: 'INV-1044', status: 'Paid', amount: 1450 },
  { id: 'INV-1045', status: 'Draft', amount: 310 },
];

type Column = 'id' | 'amount';

type Sorted = { column: Column; direction: 'ascending' | 'descending' };

const dollars = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

export default function SortableTable() {
  const [sorted, setSorted] = useState<Sorted>({ column: 'id', direction: 'ascending' });
  const rows = [...INVOICES].sort((a, b) => {
    const order = sorted.column === 'id' ? a.id.localeCompare(b.id) : a.amount - b.amount;
Invoices this quarter
Status
INV-1042Paid$1,200.00
INV-1043Overdue$980.00
INV-1044Paid$1,450.00
INV-1045Draft$310.00

Table.SortButton is a native <button>. It draws the sort glyph of GlyphsProvider after the label, an arrow pointing up by default: it shows on a sorted column and turns for a descending one. An unsorted column hides it on every screen, touch screens included, but keeps its space, so the column keeps its width once it is sorted; keyboard focus shows it there, dimmed, and so does hover on a device with a hovering pointer. Its look follows the header cell's data-sort, so a wrapper around Table.HeaderCell keeps working. After a click it waits for the cell's aria-sort or data-sort to change, however your code changes it, until the user's next press or key (a lone modifier key, such as Control to quiet a screen reader, doesn't count), and announces the result once through useAnnouncer: the sortedAscending, sortedDescending or sortCleared string of StringsProvider, with the button's aria-label or text as the column name. A Table.SortButton needs hooks, so it comes from @tounsoo/todae, not from @tounsoo/todae/table, and goes in a client component.

Selecting rows

Selection state is useSelection and Checkbox.Root: the hook keeps the selected keys and its getters give each checkbox its props. A header checkbox from getSelectAllProps() is checked when every row is selected and mixed when some are. Table.Row takes selected, which only sets data-selected and a fill: it adds no aria-selected, which does not apply to a row of a table that is not a grid, so the row's checkbox carries the state for assistive technology.

import { Checkbox, Table, useSelection, VisuallyHidden } from '@tounsoo/todae';

const PEOPLE = [
  { id: 1, name: 'Ada Lovelace', role: 'Analyst' },
  { id: 2, name: 'Grace Hopper', role: 'Engineer' },
  { id: 3, name: 'Alan Turing', role: 'Researcher' },
  { id: 4, name: 'Edsger Dijkstra', role: 'Engineer' },
  { id: 5, name: 'Barbara Liskov', role: 'Researcher' },
];

export default function SelectableTable() {
  const selection = useSelection({ keys: PEOPLE.map((person) => person.id), defaultValue: [2] });
  return (
    <Table.Root>
      <Table.Caption>Team</Table.Caption>
      <Table.Head>
        <Table.Row>
          <Table.HeaderCell scope="col">
            <Checkbox.Root {...selection.getSelectAllProps()}>
              <VisuallyHidden.Root>Select all rows</VisuallyHidden.Root>
Team
NameRole
Ada LovelaceAnalyst
Grace HopperEngineer
Alan TuringResearcher
Edsger DijkstraEngineer
Barbara LiskovResearcher

Holding Shift while clicking a row's checkbox, or while pressing Space on it, selects or clears every row from the last one toggled to this one. Restyle the fill through table.row.bg.selected.

Accessible composition

Todae handles: The native <table>, <caption>, <th> and <td> the parts render keep their meaning, and the styles give header cells their own weight and color, so they stand out without a shade. A Table.HeaderCell with sort sets aria-sort for a sorted column. Table.SortButton is a real button, takes focus, shows a focus ring and announces the new order after its own click. Table.Row selected styles the row and sets no ARIA.

You supply: A name for the table: a Table.Caption, or aria-labelledby pointing at a heading. A Table.HeaderCell with scope for every header, as above. For a table wider than its container, a ScrollArea with axis="inline", focusable and an aria-label, so keyboard users can scroll it. The sorting itself, and a name for each row's checkbox that says which row it selects, such as "Select Ada Lovelace", with a name such as "Select all rows" for the header's.

Watch for: A table drawn from divs, which has no rows or headers for assistive technology. Bold Table.Cell cells used as headers. A row made clickable with onClick on Table.Row: it takes no focus, so put a link or button in a cell. aria-sort on more than one column: set sort to 'ascending' or 'descending' on the sorted column and 'none' on the others. A Table.SortButton outside a header cell: there is no data-sort for its glyph or announcement to read.

When to use

When: Data people compare across rows and columns, with sorting by column and selecting rows when the data needs them. For search, bulk actions and pages around them, start from the Data table recipe.

When not: Laying out content that is not tabular → Stack or CSS grid. Column resizing, virtual scrolling, cell editing or arrow-key navigation between cells → a data grid, which is out of scope for Todae.

Props

Table.Root props
NameTypeDescription
childrenReact.ReactNode

A Table.Caption, then Table.Head, Table.Body and Table.Foot with their rows and cells.

Table.Caption props
NameTypeDescription
childrenReact.ReactNode

What the table holds.

Table.Head props
NameTypeDescription
childrenReact.ReactNode

Table.Row parts with the column headers.

Table.Body props
NameTypeDescription
childrenReact.ReactNode

Table.Row parts with the data.

Table.Foot props
NameTypeDescription
childrenReact.ReactNode

Table.Row parts with the totals.

Table.Row props
NameTypeDescription
selectedboolean

Marks the row selected: sets data-selected and a fill from the table.row.bg.selected token. It sets no ARIA; the row's checkbox carries the state.

childrenReact.ReactNode

Table.HeaderCell and Table.Cell parts.

Table.HeaderCell props
NameTypeDescription
scopestring

Which cells it heads: col, row, colgroup or rowgroup. Use col in Table.Head and row for the first cell of a body row.

sort"ascending" | "descending" | "none"

The column's sort state. Sets data-sort, and aria-sort for ascending and descending; none leaves aria-sort off.

childrenReact.ReactNode

The header text.

Table.Cell props
NameTypeDescription
childrenReact.ReactNode

The cell content.

Table.SortButton props
NameTypeDescription
childrenReact.ReactNode

The column label. It names the button, and the announcement uses its text, or aria-label when set.

onClick(event: React.MouseEvent<HTMLButtonElement>) => void

Where the product sorts. It runs first; calling preventDefault() skips the announcement.