Selection
Selection is a legacy migration surface: the Rust crate's selection column — a stack of checkbox-shaped (or radio-shaped) rows built from a list of keys — the drawn shape is real, the native control is not; see Accessibility, plus a "select all" row on top driven by the host's own list of every selectable key. It renders the column only: no table, no header, no rows of data.
New code should not mount it next to a table. HkTable carries its own selection: selectable adds the leading checkbox column and its select-all header itself, and the chosen rows are reported through v-model:selectedRows. Selection over a grid of tiles rather than rows is HkSelectionGrid / HkSelectionWaterfall.
- Reach for Selection while migrating a Rust page that renders this column beside its cells; on a new table use HkTable's selectable.
- Its per-row sibling is RowSelection — one self-drawn checkbox for one row, where Selection draws the input for every row itself — see the input defect under Accessibility before you rely on it.
- A lone checkbox with a label is HkCheckbox; a filter value chip is FilterChip.
Import
use *; // Selection, SelectionType
use *; // SelectionProps, rsx!, VNode
Selection is a plain function, Selection(SelectionProps { … }). Every field may be omitted inside rsx!: row_keys and available_keys default to empty lists, selection_type to SelectionType::Checkbox, fixed_column to false, class to "" and on_change to None — but total_rows has a hand-written default too, 0, which the component never reads, so the count of rows comes from available_keys alone. SelectionProps is in the prelude; SelectionType is not, so a host that names the enum takes it from hikari_components (an enum value written inside rsx! needs no import).
Checkboxes and the select-all row
The outer <div> is hk-row-selection hk-selection-column, plus hk-selection-fixed when fixed_column is on; an inner <div> repeats hk-selection-column (and hk-selection-fixed) and holds the rows. Each key becomes one div.hk-selection-row → label.hk-selection-item → input.hk-selection-checkbox with the key as its text.
For the checkbox type one more row is appended after the key rows: div.hk-selection-header → label.hk-selection-all → an input with no text and no label of its own. Its checked follows the "all selected" signal, which the component derives from available_keys — not from total_rows.
Radio, pre-selected keys and a fixed column
selection_type: SelectionType::Radio swaps the input type and gives every input the shared name="hk-selection-radio-group", so the browser treats them as one group — and the select-all row disappears. row_keys is the host's current selection: it seeds the checked inputs and is the value the component keeps as the user presses. fixed_column is a class only (hk-selection-fixed); the sheet marks the fixed variant, the positioning is the table's.
class is appended after the palette classes on the outer <div> and is the column's only styling hook — there is no style prop.
What the press does
on_change is an EventHandler<Vec<String>>; it fires with the new key list after a press — the pressed key is removed when already selected, added when not, and for radios the list is cleared to just that key. The select-all row writes an empty list when everything is selected and the whole available_keys list otherwise, and calls the same handler.
A snapshot is declarative and runs no handler, so an example only shows the state row_keys produced. Note also that a radio column press appends the key to a list; the visual "only one" comes from the radios sharing a name, not from the component enforcing a single key.
API
Rust
Props — Selection
| Prop | Type | Default | Description |
|---|---|---|---|
| row_keys | Vec<String> | [] | — |
| selection_type | SelectionType | SelectionType::Checkbox | — |
| fixed_column | bool | false | — |
| total_rows | u32 | 0 | — |
| available_keys | Vec<String> | [] | — |
| class | String | "" | — |
| on_change | Option<EventHandler<Vec<String>>> | None | — |
Accessibility
- The inputs never become native controls. The mirror writes the attribute name as a raw identifier (r#type), which rsx emits verbatim, so the rendered markup is <input name="" r#type="checkbox" class="hk-selection-checkbox"> — a type attribute never appears and the browser treats the element as a plain text input. Verified by rendering the component: three rows produce three such elements. Until the source writes a literal "type" key, do not describe these as checkboxes or radios, and give any real form a host-drawn control instead.
- Because of that, the key text is clickable only through the <label> wrapper the mirror also emits — the click still toggles the row state, but assistive technology announces an untyped input, not a checkbox.
- The select-all input has no accessible name at all: it sits in a label with no text, no aria-label and no title. A screen-reader user hears an unnamed field with nothing attached; give the column a real header cell with text (or a caption on the table) so the meaning is available.
- There is no aria-checked="mixed" on the select-all input: the component tracks an "indeterminate" signal but never writes it to the DOM, so a partial selection is not announced.
- Nothing is given a group role or a name, and the rows are plain divs: the column is not announced as a list, and the names of its rows are only read one by one.
- Rows carry no aria-selected / aria-current; when the column sits inside a table, the row semantics come from the table, not from this component.
Related components
- HkTable — the Vue table with a built-in selection column (selectable + v-model:selectedRows); the replacement for a hand-placed Selection.
- RowSelection — the self-drawn single-row checkbox.
- Cell — the data cells that sit beside this column.
- HkSelectionGrid — selection over tiles rather than table rows.
- Table — the component page for the Rust table this column was written for.