Skip to the page
Supply UI

Sort header

In code: SortHeader

A column heading that sorts the table when pressed

Preview

2026-11-14Otis Brandt£45.50
2026-11-13Mira Kovac£80.00
2026-11-12Noor Haddad£120.00

Use

The code of the preview above
import { SortHeader, Table } from '@/components/ui';

function SortHeaderDemo() {
  const [by, setBy] = useState<'date' | 'who' | 'amount'>('date');
  const [dir, setDir] = useState<'ascending' | 'descending'>('descending');
  const rows = [...PAYMENTS].sort((a, b) => (a[by] < b[by] ? -1 : a[by] > b[by] ? 1 : 0) * (dir === 'ascending' ? 1 : -1));
  const sort = (key: typeof by) => () => {
    setDir(by === key && dir === 'descending' ? 'ascending' : 'descending');
    setBy(key);
  };
  return (
    <div className="ui-grow">
      <Table scroll>
        <thead>
          <tr>
            <SortHeader direction={by === 'date' ? dir : undefined} onSort={sort('date')}>Date</SortHeader>
            <SortHeader direction={by === 'who' ? dir : undefined} onSort={sort('who')}>Customer</SortHeader>
            <SortHeader className="ui-num" direction={by === 'amount' ? dir : undefined} onSort={sort('amount')}>Amount</SortHeader>
          </tr>
        </thead>
        <tbody>
          {rows.map((row) => (
            <tr key={row.date}>
              <td className="ui-mono">{row.date}</td>
              <td>{row.who}</td>
              <td className="ui-num">£{row.amount.toFixed(2)}</td>
            </tr>
          ))}
        </tbody>
      </Table>
    </div>
  );
}

This page as text, for an AI

Options

OptionTypeWhat it does
direction "ascending" | "descending"How the table is sorted by this column now.
onSort () => voidRuns when the heading is pressed; change the sort and pass the new direction.

It also takes the 285 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.

Without React

The same look on any HTML, with the classes th[aria-sort] > button.ui-sort.

With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:

components/table-sorting-chosen-rows.css

Showing things: states, do and don’t

A column heading that sorts the table; a chosen row is aria-selected="true".

States. Lists, tables and boards have three more states besides their content: empty (Empty, with the first action inside), loading (Skeleton) and failed (Alert tone="danger"). A chosen row shows in ink, never in the brand colour.

Do

  • Put numbers, dates and codes in ui-mono (in a table cell, ui-num, which also aligns them).
  • Let a Table turn into blocks on a phone; give it scroll only when it is read down its columns.
  • Show a status in words and colour together (Badge tone="success" with "Paid"), never colour alone.

Don't

  • Don't put a card round a Table, List, Cells, Calendar or Empty: they draw their own box.
  • Don't truncate a name or a price to fit; let it wrap. Truncate only file names and addresses.
  • Don't use the status colours (success, warning, danger, info) for anything but those meanings.