TableSortButton turns a column head into a sort key: the column's name in the head's label role and a play glyph that points up for ascending and down for descending (an open diamond while the column is not sorted). It writes aria-sort on its header cell and reports the next order through onSortChange.
Example#
Usage#
Use a sort button in a column head when people need to reorder a table by that column: projects by score, invoices by date. It writes aria-sort on its head cell and reports the next order through onSortChange; the table sorts its own rows.
- States. Ascending points the glyph up, descending down; an open diamond marks a column that can be sorted but is not.
- One sorted column at a time; the others return to the diamond.
Anatomy#
- Label
data-mk-part="label" - Mark
data-mk-part="mark"
Volume#
Reading layer: identical at every volume.
Quiet
Projects by score Project Fernlight 98 Pebblepath 91 Studio
Projects by score Project Fernlight 98 Pebblepath 91 Press
Projects by score Project Fernlight 98 Pebblepath 91 Rave
Projects by score Project Fernlight 98 Pebblepath 91
Content#
- The label is the column's name; the order is in the glyph and
aria-sort, never in extra words.
Do and don't#
Do
| Project | |
|---|---|
| Fernlight | 98 |
| Pebblepath | 91 |
Don't
Every column sortable, including the notes column nobody sorts.
Accessibility#
- The header cell, not the button, carries
aria-sort, so screen readers announce the order with the column. - The order never rests on colour: the glyph's direction and shape say it.
- A plain button: Tab reaches it, Enter and Space sort.
| Keys | What happens |
|---|---|
| Tab | Moves to the sort key in a column head |
| EnterorSpace | Sorts the column (ascending, then descending) |
The colour pairs it prints, with their contrast on both papers:
| Text | Surface | Role | Bone | Night |
|---|---|---|---|---|
--mk-text | --mk-surface | ui | not in this look | not in this look |
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
sort required | TableSort | none | |
onSortChange | ((next: Exclude<TableSort, "none">) => void) | none | |
children required | ReactNode | none | The column's name. |
Tokens#
System tokens (3)
Changelog#
Arrived in 0.9.0.
CharacterCount,TableSortButton(in./table) andBeforeAfter. Read the whole entry