Sort
Sort is a legacy migration surface: the Rust crate's sort bar — one <button> per sortable column from the columns list, each printing the column title and a direction glyph, plus a "Clear" button that appears only while a direction is set. It draws the controls and reports the next sort state; it never sorts anything itself, and it renders no table.
New code should sort through HkTable, which makes a column header itself the sort control: sortable on the table or on a single column arms it, the header cycles ascending → descending → off, and the rows are re-ordered in the component.
- Reach for Sort while migrating a Rust page whose table is hand-drawn and needs the bar beside it; on a new table use HkTable's sortable.
- Sort is a bar of columns; HkTable's sorting lives in the headers. The two never coexist in one table.
- A sort filter over records rather than a column bar is FilterBar; a single selector is HkSelect.
Import
use *; // Sort, SortDirection, SortConfig, ColumnDef
use *; // SortProps, ColumnProps, rsx!, VNode
Sort is a plain function, Sort(SortProps { … }). Inside rsx! column defaults to "", direction to SortDirection::None, columns to an empty list, class to "" and on_sort_change to None — so a bar with no columns is legal and renders an empty div.hk-sort. SortProps is in the prelude; SortDirection, SortConfig and ColumnDef are not, so a host that names them takes them from hikari_components (enum values written inside rsx! need no import).
The bar
The container is div.hk-sort (a wrapping flex row with an 8px gap), and class is appended after it. Only columns whose sortable flag is on get a button — hk-sort-button, plus hk-sort-active when that column is the active one and the direction is not None. Each button holds span.hk-sort-title (the column's title) and span.hk-sort-indicator, the glyph.
Direction and the Clear button
The direction shows as a character, not an icon: ⇅ when nothing is sorted, ↑ for ascending and ↓ for descending — the active column's indicator gets the arrow, every other column keeps ⇅. When direction is not None a trailing button.hk-sort-clear is appended, holding the text "Clear" and a small cross SVG; it reports an empty column with SortDirection::None.
SortDirection::toggle walks None → Ascending → Descending → None, and SortDirection::icon is what yields the three glyphs. The deprecated SortDirection::class still exists for source compatibility but returns hk-sort-asc / hk-sort-desc, which no component emits and no sheet styles.
What a press reports
on_sort_change is an EventHandler<SortConfig>, where SortConfig carries column and direction. Pressing the active column calls SortDirection::toggle; pressing a different column always starts at SortDirection::Ascending. The Clear button calls it with an empty column and SortDirection::None. The host applies the order and feeds the new column / direction back; the component holds no state of its own, and a snapshot never runs the handler.
API
Rust
Props — Sort
| Prop | Type | Default | Description |
|---|---|---|---|
| column | String | "" | — |
| direction | SortDirection | SortDirection::None | — |
| columns | Vec<ColumnDef> | [] | — |
| class | String | "" | — |
| on_sort_change | Option<EventHandler<SortConfig>> | None | — |
Accessibility
- Every control is a real <button>, so it is in the tab order, Enter and Space activate it, and a screen reader announces a button named by its text ("Name", "Qty", "Clear").
- The direction is carried by a glyph (⇅ / ↑ / ↓) that a screen reader may read as a symbol or skip; no aria-sort is written anywhere, and the active button gets no aria-pressed. A user who cannot see the glyph has no announcement of which column is sorted or in which direction.
- The active state is a class (hk-sort-active) used for the colour of the indicator; the non-active columns' glyphs and titles are identical otherwise, so the two states differ only by colour and by the arrow.
- The clear button's name is its visible text, "Clear", with no further context — in a bar of columns it does not say which sort it clears. Position it next to the bar with the host's own text when the meaning is not obvious.
- Columns that are not marked sortable produce no button at all, so the absence is announced by nothing.
Related components
- HkTable — the Vue table whose column headers are the sort control, with the ordering applied for you.
- Cell — the data cells the bar sorts.
- Selection — the selection column usually placed beside the sorted columns.
- FilterBar — narrowing a list rather than ordering it.
- Table — the component page for the Rust table this bar was written for.