Table
Twelve admin screens share one recipe. This is it.
Anatomy
┌─ overflow-x-auto ────────────────────────────┐ ← scroll container
│ USER ROLE STATUS JOINED │ ← thead, surface-subtle
├──────────────────────────────────────────────┤
│ [av] Amara Admin Verified Mar 04 │ ← row, hover
│ [av] Tobias User Unverified Aug 19 │
└──────────────────────────────────────────────┘
rounded-control · border · divide-divider
The scroll container is not optional. A wide table scrolls inside its own rounded box; without it a single long cell makes the entire page scroll sideways, which on a phone is indistinguishable from a broken layout.
Columns
Passed as data, not markup:
<x-ds::table :columns="[
'User',
['label' => 'Role', 'width' => 'w-16'],
['label' => 'Resumes', 'align' => 'center', 'width' => 'w-20'],
['label' => '', 'width' => 'w-14'],
]">
An empty label still reserves its width — that is how an actions column keeps
its space without inventing a heading for it. Headers use the overline style
(12/16, medium, 0.05em, uppercase) at fg-muted.
Sorting
Presentation only: the component says which column the rows are sorted by and gives each sortable header a way to ask for an order. It never reorders rows.
│ REPORT ⇕ STATUS TOTAL ▾ │ ⇕ only on hover/focus · ▾ the sorted column
- A column opts in with
sortableand akey; the table takessort(a key) anddirection(asc|desc, anything else reads asasc). - Header control. A sortable header's content is a link (
sortUrlpattern or closure, default the current URL withsort,directionand nopage; in a Livewire update, where the current URL is Livewire's endpoint, the page's URL from the update's same-host Referer, else Livewire's record of the page's path, batch 30D) or, withsortAction, abutton type=buttonwith thatwire:click. The label is in a span, the arrow anaria-hiddenmini icon.group/sort -mx-1 px-1 rounded-chip inline-flex gap-1, the focus ring of every other control,hover:text-fg. - Next direction. The sorted column asks for the opposite; every other
asks for
asc. - States. Sorted: label
text-fg,chevron-up(asc) orchevron-down(desc) intext-fg, always shown, andaria-sorton theth. Sortable, not sorted:chevron-up-downinfg-subtleat opacity 0, raised to 1 ongroup-hoverandgroup-focus-visible,motion-safefade atduration-hint-enter; the space is kept so nothing moves. Right-aligned:flex-row-reverse, arrow inside. - One
aria-sort. Only the sorted column has it. "none" is not written on the rest: it would add a word to every header for no information. - No key, no sort. A sortable column without a key throws, naming the
column, at render time: a header that links to
?sort=would sort by nothing, silently. - Unchanged without it. A table with no sortable column renders
byte for byte what it did before sorting existed;
TableUnchangedTestholds the 1.x output.
Single column only. Multi-column sort, resizing and client-side sorting are not built.
Cells
<x-ds::table-cell> defines its own type — body at fg-body. The
hand-written cells set nothing and inherited the browser default, which is
16px: a size nobody chose, showing wherever a cell held bare text.
| Prop | Use |
|---|---|
align | left (default), center, right |
nowrap | Dates and counts. Not prose — a cell that refuses to wrap is what forces the scroll container to appear. |
rowHeader | <th scope="row">, font-medium text-fg: the cell that names the row. Same padding and alignment as a td; without it the cell is the td it always was. |
Numbers that are compared down a column want tabular-nums; add it per cell
rather than globally, since it costs legibility on text.
Head slot and bodies
A head slot is the thead's rows (thead.bg-surface-subtle, its own
attributes merged); it wins over columns. A default slot whose first tag
is <tbody is printed as it is, one tbody per group; anything else goes in
the table's tbody.divide-y. Until 2.0 a block wrote its thead and
tbodys into the rows slot, and the browser's parser moved them out of the
table's tbody, leaving an empty one.
Sticky head and first column
stickyHead and stickyFirst print data-ds-table-sticky-head /
-first on the scroll container; the rules are theme.css's, in
@layer components so a cell's own background utility wins:
| Prop | Cells | Stuck where |
|---|---|---|
stickyHead | thead > tr > th, surface-subtle, z 2 | top: 0 in the scroll box: it needs a height (max-h-*) to scroll in |
stickyFirst | each row's first cell (and second with selectable, at inset-inline-start: 3rem), surface, z 1; the head's at z 3 | inset-inline-start: 0 |
A sticky cell is opaque: the card, a hovered row's surface-subtle (rows
with the hover class only), and a selected row's accent-wash as an image
over the card, since the wash is translucent in dark.
The shadow is a pseudo-element on the stuck cells (::after under the head,
::before beside the column, flipped in right-to-left), its opacity driven
by the scroll box's own scroll timeline over the first 1rem with the scroll
area's ds-scroll-edge-in keyframes, so it is absent until something has
moved under it. Without scroll-driven animations there is no shadow.
Loading
loading replaces the body with a hidden row saying loadingLabel and
loadingRows rows of one-line skeletons (aria-hidden), one cell per
column (plus the box column), and adds aria-busy="true" to the table. The
slot is not printed. Chosen over making skeleton-swap hold rows: its
wrapper is a div, which a tbody cannot contain, and a table that keeps
its head while loading does not move when the rows land.
Rows
Rows hover by default, because in this app almost every row is clickable
somewhere. Pass :hover="false" for a genuinely inert row — a hover affordance
on something that does nothing is a lie, and the empty-state row is the usual
case.
Selection
selectable (batch 25): rows given a value draw a first cell holding a
ds::checkbox (hidden label selectLabel, name = selectName,
data-ds-select-row, x-model = selectModel when set, a stable id hashed
from field and value), and tint when checked
(has-[[data-ds-select-row]:checked]:bg-accent-wash). With columns the
header starts with a select-all cell, rendered hidden and shown by
dsRowSelect, which keeps it mixed or full and adds Shift-press ranges (and
Shift+Space on a focused box: the key is remembered from its keydown, since
the click a key makes does not carry Shift in every browser). The
rows read the table's settings through @aware (selectable,
selectName, selectModel). A table without selectable, and a row
without a value, render exactly as before. Not with tree (it throws:
both want the first cell). The bulk actions are ds::selection-bar; see
specs/selection-bar.md.
Tree table
tree on the table, level (and expandable, open, parent) on each
row: the WAI-ARIA treegrid, rows focused rather than cells.
- Flat rows, structure from level and order. A
<tr>cannot nest, and a table of nested tables loses its columns. A row's children are the rows after it one level deeper, up to the next row at its level or above.parentis optional and only checked. - Counted in PHP (
Support\TreeGrid::rows(), on the rendered body):aria-setsizeandaria-posinsetper sibling group,tabindex="0"on the first row,data-ds-row-hiddenunder every closed row. It throws on a level that jumps by more than one, on rows under a row that is neitherexpandablenoropen, and on aparentthat does not match. A row's attributes are written in a fixed order so the pass can find them. - Hidden by attribute, not
hidden. Preflight's[hidden] { display: none !important }cannot be undone by a utility, and with JavaScript off every row must show. The row's class is[@media(scripting:enabled)]:data-ds-row-hidden:hidden; the toggles arenoscript:invisible. - The toggle is a
button tabindex="-1"before the first cell's content, indented by--ds-level: the row is the Tab stop, and a mouse still has a target. Its name is "Expand" or "Collapse" (read from the row'saria-expanded) and the cell's words. The chevron isds::icon-swap, mirrored in RTL. dsTreegrid(shared/tree-nav.js, asds::tree): one stop, Up, Down, Right, Left, Home, End,*, type-ahead; Enter follows the first link in the row or toggles. Closing hides the rows below without touching their ownaria-expanded, so reopening restores them.expand/collapsebubble with{ id }.- Sorting stays the host's: sort siblings in the query and keep children after parents.
Empty state
A full-width cell with colspan covering every column, an icon, and a sentence.
It keeps the header visible: the reader needs to know what is empty, and a
table that collapses to a bare message loses that.
Do not
- Reach for a table to lay out a card grid. If the columns do not mean the same thing on every row, it is not a table.
- Put a table inside a panel. Both draw a bordered container with a header; you get a double frame and two competing rules. Pick one.
- Sort the rows in the view or in Alpine. The order is the query's.
- Nest
<tbody>or tables for a tree. Usetreeandlevel. - Hide a tree row with
hidden. See Tree table. - Right-align text. Right alignment is for numbers, where it lines up the units — on text it just makes the left edge ragged and the row hard to track.
From the package repo: edit this page on GitHub.