Checkbox

Checkbox

HkCheckbox is the independent on/off choice: a square box with a check glyph, an optional caption, and a third state — indeterminate — that draws a dash for "some of the things below are selected". It is controlled only: the host passes modelValue and listens for update:modelValue. The same component also renders the round variant (type="radio"), which is one row of a radio set.

  • For a choice that excludes its siblings — exactly one of a set — use HkRadio, which owns the whole group and its options.
  • For a setting that takes effect at once, with no form submit, use HkSwitch.
  • For a numeric value picked along a range, use HkSlider or the stepper field HkNumberInput.

Import

tsx
1
import { HkCheckbox } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // Checkbox, CheckboxSize, CheckboxType
use hikari_components::prelude::*; // rsx!, VNode

The Rust form is a plain function, Checkbox(CheckboxProps { … }). Vue calls the state modelValue, a boolean that doubles as the tri-state marker (null renders the dash); the Rust mirror splits it into two flags, checked and indeterminate, because a Rust bool cannot carry null.

Checked, unchecked and indeterminate

modelValue is the whole state: true draws the check glyph, false draws an empty box, and null draws the indeterminate dash. A click on the dash reports true — the browser clears the dash and checks the box — so the same control can stand for "all of the rows below" and settle itself. In the Rust mirror that first box is the pair checked: false / indeterminate: true. The Vue example below is live: click the boxes to see the state follow the click.

HkCheckbox declares modelValue as a Boolean prop, so the null arm is a runtime state rather than a declared TypeScript type; a host that drives the dash keeps its own boolean | null state and passes it through. The page's examples stay on the declared type.

Sizes and the radio variant

size — sm / md (the default) / lg — scales the box, the glyph and the caption together. type="radio" swaps the square box and its check glyph for a round box with a dot, and indeterminate is ignored on that arm: a radio has no third state.

Disabled, caption and change

disabled dims the control, takes it out of the Tab order and silences the change: a click reports nothing. The caption is label, and the default slot wins over it when a caller needs markup rather than text — the same order the Rust mirror keeps between label and its children element. Every accepted toggle emits update:modelValue with the checked state the browser now reports; wire your own state there.

The Rust examples in this section attach an event handler; the fences run without a browser, so the output is the rendered snapshot.

API

Vue

Props

NameTypeDefaultRequired
modelValueBooleanfalse—
labelStringundefined—
disabledBooleanfalse—
type<code>String as PropType<"checkbox" | "radio"></code>"checkbox"—
size<code>String as PropType<"sm" | "md" | "lg"></code>"md"—

Emits

EventPayload
update:modelValueboolean

Rust

Props — Checkbox

PropTypeDefaultDescription
checkedboolfalseControlled checked state (Vue: modelValue, default false).
indeterminateboolfalseControlled indeterminate marker (Vue: modelValue === null).
disabledboolfalse—
input_typeCheckboxTypeCheckboxType::CheckboxNative input kind (Vue: type).
sizeCheckboxSizeCheckboxSize::Md—
labelOption<String>NoneLabel text; the default slot (children) wins over it when present.
on_changeOption<EventHandler<bool>>NoneEmitted with the checked state after a toggle; a no-op while disabled.
childrenElement(empty)Rich label content (Vue: the default slot).
classString""Vue attribute fallthrough onto the root <label>.
styleString""—

Accessibility

  • The root is a <label> and the native <input type="checkbox"> sits inside it, so a click anywhere on the caption or the box activates the control, and the caption is its accessible name with no id wiring.
  • The input owns the role and the checked state; the component adds no aria-checked of its own, because that would announce the state twice.
  • The indeterminate state is the browser's own indeterminate flag on the input; the dash is drawn beside it and is not a second state to describe.
  • disabled uses the native attribute, so the control leaves the Tab order and is announced as unavailable.
  • The focus ring is drawn on the box from the nested input's :focus-visible, so the keyboard focus is visible even though the input is transparent.

Related components

  • HkRadio — the single-choice sibling, one row per option with a group around them.
  • HkSwitch — the immediate on/off setting.
  • HkSlider — a choice along a numeric range.
  • HkFormField — the caption and message shell for a control that needs a label line.