Select

Select

HkSelect is the dropdown choice field: a caption, a trigger button that shows the chosen option's label (or the placeholder while nothing is picked) and a chevron, and — once opened — the option list. On a desktop the list is an anchored popout; below 768px it becomes a bottom sheet instead. Reach for it when one value comes out of a fixed, ordered list and the full set is too long to show at once.

  • A handful of options that all fit on the page are better as one control each: HkRadio for one pick, HkCheckbox for many.
  • An on/off decision is a HkSwitch, and a value on a continuous track is a HkSlider — both say their state without opening a surface.
  • A filter field that narrows a list as you type is an HkSearchInput.

Import

tsx
1
import { HkSelect } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // Select, SelectOption, SelectPanelPlacement
use hikari_components::prelude::*; // rsx!, VNode, Icon, MdiIcon, EventHandler

The Rust form is a plain function, Select(SelectProps { … }). Every prop may be omitted inside rsx!, and an omitted prop takes its default. The Vue form is controlled (modelValue + update:modelValue); the Rust form is a still, so its examples pass the value the field holds. Both forms keep the disclosure state — and, in Rust, the highlighted row — outside the component; see Opening and highlighting.

Options and states

options is the list: each entry carries a value (what gets emitted), a label (what the row and the trigger read) and an optional disabled. The trigger shows the label of the option matching modelValue; when nothing matches, the raw value is shown, and while modelValue is empty the placeholder stands in. label draws the caption, required appends the * marker, error turns the trigger red and prints a line under it, and disabled greys the whole field and takes it out of the tab order.

The panel is not in the snapshot: a screenshot of this page shows every stage below with its trigger only, closed. The first stage of the next section shows the opened popout instead — a still cannot press a button, so that example presses the trigger itself once the field has mounted.

This language is not enabled for the project.

The opened surface

Pressing the trigger toggles the surface. On a desktop it is a popout anchored to the trigger, with placement deciding the side and the alignment — bottom-start (the default), bottom-center, bottom-end, top-start, top-center, top-end — and it grows upward for the top-* values, which is what a field pinned to the bottom of the viewport needs. Below 768px the same list docks as a bottom sheet with a grabber, a title and a ✕, whatever placement says. panelTitle names the opened surface without drawing a caption on the field itself, so a field labelled by a titled row around it still registers the surface with a name.

The Vue example presses its own trigger after mounting, which is the only way a still can show the opened panel: the popout is anchored to the field, lists the same options with the current one marked, and every row is a plain div — pressing the trigger on the live page toggles the surface.

Opening and highlighting

The disclosure is internal to Vue: the component owns isOpen, and pressing the trigger flips it. The Rust mirror has no per-instance state to hold, so there the same flag is a prop pair — open + on_open_change, which reports the requested state for a trigger press, a row commit, Escape or a click outside the field, and the host writes it back. A Vue caller reads the chosen value from update:modelValue; it does not need to bind open.

Highlighting is a second pair, and it is the one real difference between the two forms. Vue keeps highlightedIndex in a local ref, seeds it with the current selection when the panel opens, and moves it with the arrow keys and the pointer. The Rust mirror has no per-instance state to hold, so the index is highlighted_index + on_highlight_change: the host stores it and passes it back, and the rows draw their data-highlighted from whatever the host last recorded. On a desktop popout the rows also report a pointer hover through the same channel.

Picked so far: none

API

Vue

Props

NameTypeDefaultRequired
modelValueString""—
labelStringundefined—
panelTitleStringundefined—
placeholderString""—
errorStringundefined—
disabledBooleanfalse—
requiredBooleanfalse—
optionsArray as PropType<HkSelectOption[]>() => [] as HkSelectOption[]—
placementString as PropType<SelectPanelPlacement>"bottom-start"—
aboveChromeBooleanfalse—

Emits

EventPayload
update:modelValuestring

Rust

Props — Select

PropTypeDefaultDescription
model_valueString""Vue: modelValue, default "".
labelOption<String>NoneVisible caption above the trigger (Vue: label).
panel_titleOption<String>NoneTitle for the OPENED surface only (mobile sheet heading, popout a11y name).
placeholderString""Shown while the model is empty (Vue default "").
errorOption<String>NoneError ink + message line (data-error on the trigger).
disabledboolfalse—
requiredboolfalseAppends the * marker to the caption (Vue: required).
optionsVec<SelectOption>[]The option model.
placementSelectPanelPlacementSelectPanelPlacement::BottomStartDesktop-popout placement (Vue default "bottom-start").
openboolfalsePanel visibility (Vue: the local isOpen).
highlighted_indexi32-1Keyboard/pointer highlight index; -1 means "none" (Vue: the local highlightedIndex).
sheet_on_mobilebooltrueDock as a bottom sheet below 768px (Vue panel default: true).
offsetf644.0Gap between the trigger and the popout, in px (Vue panel default 4).
match_anchor_widthbooltrueTie the popout's minimum width to the trigger (Vue panel default true).
anchorOption<SelectAnchorRect>NoneThe trigger rect to anchor against.
max_heightOption<String>NoneCap for the DESKTOP POPOUT, as any CSS length (Vue panel maxHeight, published through --hk-select-panel-max-height on the popout only).
classString""—
on_open_changeOption<EventHandler<bool>>NoneFires with the desired open state (Vue: update:open).
on_value_changeOption<EventHandler<String>>NoneFires with the chosen option value (Vue: update:modelValue).
on_highlight_changeOption<EventHandler<i32>>NoneFires with the desired highlight index (the Rust-side stand-in for Vue's local highlightedIndex writes).
nativeboolfalseRender a native <select> instead of the mirrored trigger and popout: the platform's own menu, keyboard and mobile picker, one <option> per option, and none of the sheet's classes — class and attrs land on the element.
attrsVec<(String, String)>[]Attributes set on the native <select> by name — name, title, data-*, aria-*, test hooks.

Accessibility

  • The trigger is a real <button type="button">: Enter and Space open the field, the arrow keys step the highlight and Enter commits the highlighted row — a disabled row silently refuses the commit.
  • Escape closes the open panel and stops propagating, so one press never closes both the dropdown and the dialog it sits in. A closed field lets Escape through to its host.
  • required is drawn as the * marker on the caption, not as the aria-required attribute; pass the requirement in the surrounding copy as well if assistive technology must hear it.
  • The caption is a plain <label> with no for in either form, and the trigger carries no aria-labelledby. Keep the field's name short and repeat it in the surface title (panelTitle) when the field's own caption lives in a row header.
  • The opened surface carries aria-label from panelTitle (or label); the mobile sheet is a role="dialog" with aria-modal, so a screen reader announces the list, not the trigger's state.
  • A row is not a native control: read out its state through the labels you pass, not through selection affordances.

Related components

  • HkRadio — one pick from a short list, all options visible.
  • HkCheckbox — several picks that do not need a surface.
  • HkSwitch — an on/off state that takes no room.
  • HkSlider — a value along a continuous track.
  • HkSearchInput — a field that filters a list as you type.
  • HkFormField — the shared wrapper for a caption, a control and its message line.