Table
| Nights | |
|---|---|
| Nora Lindqvist | 3 |
| Sven Berg | 1 |
npx shadcn add @klarhimmel/tableCopy for AIExamples
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
| Guest | Room | Nights | Total (SEK) | Status |
|---|---|---|---|---|
| Nora Lindqvist | Garden room | 3 | 4 350 | Confirmed |
| Sven Berg | Seaside suite | 1 | 1 900 | Pending |
| Ida Holm | Loft | 5 | 7 250 | Confirmed |
| Total | 9 | 13 500 |
Import
Import
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
Table.caption | string | required | Required. Names the table (and the scroll region). |
Table.hideCaption | boolean | - | Keep the caption for screen readers only. |
Table.children | ReactNode | required | |
Table.className | string | - | Extra classes, merged after the component's own. |
TableHead.children | ReactNode | required | |
TableBody.children | ReactNode | required | |
TableFoot.children | ReactNode | required | |
TableRow.children | ReactNode | required | |
TableRow.selected | boolean | - | |
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.children | ReactNode | required | |
TableRowHeader.className | string | - | Extra classes, merged after the component's own. |
TableCell.align | 'left' | 'center' | 'right' | 'justify' | 'char' | 'left' | |
native attributes | HTMLAttributes | - | Every native attribute of the element passes through, className included. |
Accessibility
| Key | Does |
|---|---|
Tab | Reaches the scroll frame and any sort buttons |
Arrow keys | Scroll the frame when it is focused |
Enter / Space | Sorts 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