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
import { HkRadio } from "@celestia-island/hikari";
use hikari_components::*; use hikari_components::prelude::*;
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { HkRadio } from "@celestia-island/hikari";
import { ref } from "vue";
import type { CSSProperties } from "vue";
const column: CSSProperties = { display: "grid", gap: "24px", maxWidth: "360px" };
const transit = ref<string | number | null>(null);
export default () => (
<div style={column}>
<HkRadio
modelValue={transit.value}
onUpdate:modelValue={(value) => (transit.value = value)}
options={[
{ value: "rail", label: "Rail" },
{ value: "coach", label: "Coach" },
{ value: "flight", label: "Flight" },
]}
aria-label="How do you get there?"
/>
<span>Chosen: {transit.value ?? "nothing yet"}</span>
</div>
);
rsx! {
div { style: "display:grid;gap:24px;max-width:360px",
RadioGroup {
value: Some("coach".to_string()),
options: vec![
RadioOption::new("rail", "Rail"),
RadioOption::new("coach", "Coach"),
RadioOption::new("flight", "Flight"),
],
}
}
}
import { HkRadio } from "@celestia-island/hikari";
import { ref } from "vue";
import type { CSSProperties } from "vue";
const column: CSSProperties = { display: "grid", gap: "24px", maxWidth: "360px" };
const transit = ref<string | number | null>(null);
export default () => (
<div style={column}>
<HkRadio
modelValue={transit.value}
onUpdate:modelValue={(value) => (transit.value = value)}
options={[
{ value: "rail", label: "Rail" },
{ value: "coach", label: "Coach" },
{ value: "flight", label: "Flight" },
]}
aria-label="How do you get there?"
/>
<span>Chosen: {transit.value ?? "nothing yet"}</span>
</div>
);rsx! {
div { style: "display:grid;gap:24px;max-width:360px",
RadioGroup {
value: Some("coach".to_string()),
options: vec![
RadioOption::new("rail", "Rail"),
RadioOption::new("coach", "Coach"),
RadioOption::new("flight", "Flight"),
],
}
}
}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.
import { HkRadio } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const column: CSSProperties = { display: "grid", gap: "24px", maxWidth: "320px" };
export default () => (
<div style={column}>
<HkRadio modelValue="daily" direction="vertical" options={[
{ value: "hourly", label: "Hourly" },
{ value: "daily", label: "Daily" },
]} />
<HkRadio modelValue="daily" size="sm" options={[{ value: "hourly", label: "Hourly" }, { value: "daily", label: "Daily" }]} />
<HkRadio modelValue="daily" size="lg" options={[{ value: "hourly", label: "Hourly" }, { value: "daily", label: "Daily" }]} />
</div>
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
rsx! {
div { style: "display:grid;gap:24px;max-width:320px",
RadioGroup {
value: Some("daily".to_string()),
direction: RadioDirection::Vertical,
options: vec![
RadioOption::new("hourly", "Hourly"),
RadioOption::new("daily", "Daily"),
],
}
RadioGroup {
value: Some("daily".to_string()),
size: RadioSize::Sm,
options: vec![
RadioOption::new("hourly", "Hourly"),
RadioOption::new("daily", "Daily"),
],
}
RadioGroup {
value: Some("daily".to_string()),
size: RadioSize::Lg,
options: vec![
RadioOption::new("hourly", "Hourly"),
RadioOption::new("daily", "Daily"),
],
}
}
}
import { HkRadio } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const column: CSSProperties = { display: "grid", gap: "24px", maxWidth: "320px" };
export default () => (
<div style={column}>
<HkRadio modelValue="daily" direction="vertical" options={[
{ value: "hourly", label: "Hourly" },
{ value: "daily", label: "Daily" },
]} />
<HkRadio modelValue="daily" size="sm" options={[{ value: "hourly", label: "Hourly" }, { value: "daily", label: "Daily" }]} />
<HkRadio modelValue="daily" size="lg" options={[{ value: "hourly", label: "Hourly" }, { value: "daily", label: "Daily" }]} />
</div>
);rsx! {
div { style: "display:grid;gap:24px;max-width:320px",
RadioGroup {
value: Some("daily".to_string()),
direction: RadioDirection::Vertical,
options: vec![
RadioOption::new("hourly", "Hourly"),
RadioOption::new("daily", "Daily"),
],
}
RadioGroup {
value: Some("daily".to_string()),
size: RadioSize::Sm,
options: vec![
RadioOption::new("hourly", "Hourly"),
RadioOption::new("daily", "Daily"),
],
}
RadioGroup {
value: Some("daily".to_string()),
size: RadioSize::Lg,
options: vec![
RadioOption::new("hourly", "Hourly"),
RadioOption::new("daily", "Daily"),
],
}
}
}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.
import { HkRadio } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const column: CSSProperties = { display: "grid", gap: "24px", maxWidth: "320px" };
export default () => (
<div style={column}>
<HkRadio modelValue="team" options={[
{ value: "solo", label: "Solo" },
{ value: "team", label: "Team" },
{ value: "enterprise", label: "Enterprise, on request", disabled: true },
]} />
<HkRadio modelValue="team" disabled options={[{ value: "solo", label: "Solo" }, { value: "team", label: "Team" }]} />
</div>
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
rsx! {
div { style: "display:grid;gap:24px;max-width:320px",
RadioGroup {
value: Some("team".to_string()),
options: vec![
RadioOption::new("solo", "Solo"),
RadioOption::new("team", "Team"),
RadioOption {
value: "enterprise".to_string(),
label: "Enterprise, on request".to_string(),
disabled: true,
},
],
}
RadioGroup {
value: Some("team".to_string()),
disabled: true,
options: vec![
RadioOption::new("solo", "Solo"),
RadioOption::new("team", "Team"),
],
}
}
}
import { HkRadio } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const column: CSSProperties = { display: "grid", gap: "24px", maxWidth: "320px" };
export default () => (
<div style={column}>
<HkRadio modelValue="team" options={[
{ value: "solo", label: "Solo" },
{ value: "team", label: "Team" },
{ value: "enterprise", label: "Enterprise, on request", disabled: true },
]} />
<HkRadio modelValue="team" disabled options={[{ value: "solo", label: "Solo" }, { value: "team", label: "Team" }]} />
</div>
);rsx! {
div { style: "display:grid;gap:24px;max-width:320px",
RadioGroup {
value: Some("team".to_string()),
options: vec![
RadioOption::new("solo", "Solo"),
RadioOption::new("team", "Team"),
RadioOption {
value: "enterprise".to_string(),
label: "Enterprise, on request".to_string(),
disabled: true,
},
],
}
RadioGroup {
value: Some("team".to_string()),
disabled: true,
options: vec![
RadioOption::new("solo", "Solo"),
RadioOption::new("team", "Team"),
],
}
}
}
API
Vue
Props
Emits
Rust
Props — RadioGroup
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.