State attributes
Every state a part has is a data attribute or ARIA, present or absent, so any styling solution can read it.
A part's state is on its element, as data-* attributes and ARIA. A boolean attribute is
present (empty) or absent, never "false".
Parts
Every part carries data-grid-part: root, grid, header, header-row, header-cell,
body, row, cell, row-detail, empty, or summary, summary-row and summary-cell
(Summary rows), column-resizer on a resize handle you render
with useColumnResizer (Column resizing), group-label on a
group's label you render with useGroupLabel
(Collapsible groups and sticky labels), and row-drag-handle
on a row's handle you render with /row-reorder's useRowDragHandle (Row reordering), and group-toggle on a
group row's toggle you render with /row-grouping's useGroupToggle (Row grouping), and
fill-handle on a fill handle you render with /fill's useFillHandle (Fill handle). Rows and cells carry
their indexes: data-row-index (header rows are -1 and above, a header cell spanning rows is at
its top one; the top summary rows are before the header's, the bottom ones after the body's) and data-column-index (a header cell spanning columns is at its first). Tests
select by them, never by class names.
States
| attribute | on | when |
|---|---|---|
data-active | cell, header cell | it is the active cell |
data-active | row, summary row | it holds the active cell |
data-summary | summary, summary row, summary cell | top or bottom: where its summary rows stay (Summary rows) |
data-interacting | cell, header cell | its controls have the keys (Controls in cells) |
data-editing | cell | it is being edited: it shows its editor (Editing) |
data-fill-target | cell | a fill's drag would fill it (Fill handle) |
data-filling | fill handle | a drag on it is filling |
data-loading | row, cell | its row is not loaded yet (getRow answered undefined) |
data-empty | root, grid | the grid has no rows (Empty state) |
data-group | header cell | it is a group's (Column groups) |
data-collapsible | header cell | it is a collapsible group's, with columnGroupCollapse() (Collapsible groups) |
data-collapsed | header cell | its collapsible group is closed |
data-expanded | row | it shows its detail (Master-detail) |
data-group-row | row | it is a group row (Row grouping) |
data-group-expanded | row | it heads an expanded row group |
data-depth | row | its depth in the tree, 0 at the top, while the rows have kinds (getRowMeta) |
data-expanded | group toggle | its row's group is expanded |
data-selected | row | it is selected (Row selection) |
data-selected-cell | cell | it is in the selected range (Cell selection) |
data-range-edge | cell | the range's edges it sits on, space-separated: top, bottom, start, end (match one with ~=) |
data-pinned | cell, header cell | start or end: where its column is pinned, with columnPinning() (Pinned columns) |
data-pinned-edge | cell, header cell | its pinned part's edge: it ends at the last column pinned at the start, or starts at the first pinned at the end |
data-sortable | header cell | its column is sortable, with sorting() installed (Sorting) |
data-sort | header cell | ascending or descending, while its column is sorted |
data-sort-priority | header cell | its column's place in the sort, 1-based |
data-resizable | header cell | its column can be resized, or for a group one of its columns, with columnResize() (Column resizing) |
data-resizing | header cell, resize handle | a drag is resizing its column (or group) |
data-reorderable | header cell | its column or group can be moved, with columnReorder() (Column reordering) |
data-dragging | header cell | a drag is moving its column or group |
data-drop-target | header cell | before or after: a drag would drop beside it, on that side |
data-dragging | row, row drag handle | a drag is moving the row (Row reordering) |
data-drop-target | row | before or after: a row's drag would drop beside it, on that side |
data-reorderable | row drag handle | a press on it drags its row (the rows move, the grid is not sorted, the row is loaded) |
ARIA
| attribute | on | value |
|---|---|---|
role | grid, rowgroup, row, columnheader, gridcell | the grid pattern; treegrid on the grid while the rows have kinds (Row grouping) |
aria-level | row | its depth + 1, in a treegrid |
aria-expanded | row, group toggle | whether a group row (or a row that expands) shows its rows |
aria-setsize, aria-posinset | row | its siblings' count and its place among them, from 1, when its meta says |
aria-rowcount | grid | every row, header and summary rows included, rendered or not |
aria-colcount | grid | every column |
aria-rowindex | row, summary row | 1-based, as they show: the header rows, the top summary rows, the body rows, the bottom summary rows |
aria-colindex | cell, header cell | 1-based (a group's first column) |
aria-colspan | cell, header cell, row detail | the columns a group or a spanning cell covers, when more than one; a detail spans every column |
aria-rowspan | header cell | the header rows a column spans, when more than one |
aria-sort | header cell | the first sorted column's direction, with sorting() installed |
aria-multiselectable | grid | true when many rows can be selected, or ranges of cells |
aria-selected | row | true or false on a row that can be selected, true on one your keys select anyway (false is ARIA's own "selectable, not selected"); a group row's, true while every one of its rows is |
aria-selected | cell | true in the selected range, false outside it, while cells are selectable (Cell selection); none on header and summary cells |
role | resize handle | separator, with aria-orientation="vertical"; its name (aria-label) is yours |
aria-valuenow | resize handle | its column's width on screen in pixels (a group's: its columns') |
aria-valuemin, aria-valuemax | resize handle | the narrowest and widest it resizes to; without a maximum, the view's width (at least the width) |
Styling a state
[data-grid-part="cell"][data-active] {
outline: 2px solid var(--accent);
outline-offset: -2px;
}
[data-grid-part="row"][data-loading] [data-grid-part="cell"]::after {
content: "";
inline-size: 60%;
block-size: 0.75rem;
background: var(--placeholder);
}With Tailwind: data-active:outline-2, data-loading:opacity-50, in-data-empty:hidden,
data-group:justify-center.