Radio

Radio

HkRadio is the single-choice group: it takes an options array, draws one row per option, and reports the chosen value through update:modelValue. Only one row can be selected, and null means nothing yet — the shape a form needs before the user has answered. The group owns the rows, so there is no standalone radio to place yourself.

  • For a choice that does not exclude its siblings — any number may be on — use HkCheckbox.
  • For a setting that takes effect at once, with no form submit, use HkSwitch.
  • For a long list of mutually exclusive values, a select or an autocomplete is friendlier than a wall of radio rows; see the text-entry pages starting at HkInput.

Import

tsx
1
import { HkRadio } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // RadioGroup, RadioOption, RadioDirection, RadioSize
use hikari_components::prelude::*; // rsx!, VNode

The Rust form is a plain function, and its name does not match the Vue one: RadioGroup(RadioGroupProps { … }). Vue calls the selection modelValue (null when nothing is chosen); the Rust mirror calls it value: Option<String>, so None is that same "nothing chosen" state.

Options and the selected value

options is required and ordered: each entry carries a value, a label and an optional own disabled. modelValue names the selected option by value, and a row that is already selected emits nothing when it is clicked — the native radio only fires a change when it becomes checked. The snapshot below shows two groups, one with a choice and one still unanswered.

The Vue example is live: click a row to move the selection.

Chosen: nothing yet

Direction and size

direction is horizontal (the default) or vertical; it only sets the group's flex direction and wrapping, so a wide option list wraps instead of overflowing. size — sm / md (the default) / lg — scales the gap, the box and the caption from the same step.

Disabling rows and the whole group

disabled takes the whole group out of play; an option's own disabled disables just that row, and the two are OR-ed, so a group-level flag wins over a row that would otherwise be selectable. A disabled row is dimmed, skipped by the keyboard and emits nothing.

API

Vue

Props

NameTypeDefaultRequired
modelValue<code>[String, Number] as PropType<string | number | null></code>null—
optionsArray as PropType<HkRadioOption[]>—✓
disabledBooleanfalse—
direction<code>String as PropType<"horizontal" | "vertical"></code>"horizontal"—
size<code>String as PropType<"sm" | "md" | "lg"></code>"md"—

Emits

EventPayload
update:modelValue<code>string | number</code>

Rust

Props — RadioGroup

PropTypeDefaultDescription
valueOption<String>NoneThe selected option's value (Vue: modelValue, default null).
optionsVec<RadioOption>[]The rows, in render order (Vue: options, required).
disabledboolfalseGroup-wide disable; a row's own disabled is OR-ed with it.
directionRadioDirectionRadioDirection::Horizontal—
sizeRadioSizeRadioSize::Md—
on_changeOption<EventHandler<String>>NoneEmitted with the chosen option's value (never for the current one).
classString""Vue attribute fallthrough onto the root <div>.
styleString""—

Accessibility

  • Each option is a <label> wrapping its native <input type="radio">, so the caption text names the row and clicking anywhere on the row selects it.
  • The rows share no name attribute, so the browser does not group them natively; the component's own modelValue is what makes the set exclusive. Keep the value in your state machine rather than relying on the form's native grouping.
  • The native input owns the role and the checked state, and the component adds no aria-* of its own.
  • options has no group name; give the surrounding group an accessible name from your own markup (a fieldset with a legend, or a labelled container) when the choice matters.
  • A disabled row uses the native attribute, so it leaves the keyboard order and is announced as unavailable.

Related components

  • HkCheckbox — the independent on/off choice that can be selected alongside its siblings.
  • HkSwitch — the immediate on/off setting.
  • HkSlider — a choice along a numeric range.
  • HkFormField — the caption and message shell for a group that needs a label line.