Skip to content
Klarhimmel UI

Table

Upcoming bookings
Nights
Nora Lindqvist3
Sven Berg1
npx shadcn add @klarhimmel/table

Examples

  • Basic

  • Sortable

  • Selectable

DetailsAbout, usage, props and more

A semantic data table in a keyboard-scrollable frame, with sortable headers.

When to use

  • Use for

    Rows that share columns, compared by eye: bookings, invoices, members.

  • Not for

    Page layout, or one record's details.

  • Pairs with

    Pagination, Badge, Checkbox, Menu.

Preview

Upcoming bookings
GuestRoomNightsTotal (SEK)Status
Nora LindqvistGarden room34 350Confirmed
Sven BergSeaside suite11 900Pending
Ida HolmLoft57 250Confirmed
Total913 500
table.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Table, TableHead, TableBody, TableRow, TableHeader, TableRowHeader, TableCell } from '@/components/klarhimmel/ui/table';

export default function Example() {
  return (
    <Theme theme="brand">
      <Table caption="Upcoming bookings">
        <TableHead><tr><TableHeader>Guest</TableHeader><TableHeader align="right">Nights</TableHeader></tr></TableHead>
        <TableBody>
          <TableRow><TableRowHeader>Nora</TableRowHeader><TableCell align="right">3</TableCell></TableRow>
        </TableBody>
      </Table>
    </Theme>
  );
}

Import

Import

import { Table, TableHead, TableBody, TableFoot, TableRow, TableHeader, TableRowHeader, TableCell } from '@/components/klarhimmel/ui/table';
Files
table.tsx, in components/klarhimmel/ui/. With it: theme, utils. npm: lucide-react.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
Table.captionstringrequiredRequired. Names the table (and the scroll region).
Table.hideCaptionboolean-Keep the caption for screen readers only.
Table.childrenReactNoderequired
Table.classNamestring-Extra classes, merged after the component's own.
TableHead.childrenReactNoderequired
TableBody.childrenReactNoderequired
TableFoot.childrenReactNoderequired
TableRow.childrenReactNoderequired
TableRow.selectedboolean-
TableHeader.sort'ascending' | 'descending' | 'none'-Makes the header a sort button. Pass the current state; `aria-sort` is set on the cell.
TableHeader.onSort() => void-Makes the header a sort button and sets aria-sort. You sort the rows.
TableHeader.align'left' | 'right''left'
TableRowHeader.childrenReactNoderequired
TableRowHeader.classNamestring-Extra classes, merged after the component's own.
TableCell.align'left' | 'center' | 'right' | 'justify' | 'char''left'
native attributesHTMLAttributes-Every native attribute of the element passes through, className included.

Accessibility

KeyDoes
TabReaches the scroll frame and any sort buttons
Arrow keysScroll the frame when it is focused
Enter / SpaceSorts by the focused header

The caption names the table. Wide tables scroll inside a focusable region. You sort the rows; the header only reports and asks.

Accessibility