Skip to content

Checkbox ​

Tri-state selection control. Supports the checked / unchecked / indeterminate states and can be disabled.

Spec source: lh-ui-core/specs/checkbox.json · Golden cases: lh-ui-core/cases/checkbox.json (6 cases, translated into hypium tests)

Basic usage ​

checked is controlled; tapping toggles it and fires onChange with the new checked state.

9:41Checkbox basics

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

typescript
LhCheckbox({
  checked: this.agreed,
  label: 'Agree to the terms of service',
  onChange: (checked: boolean) => { this.agreed = checked },
})

Indeterminate and disabled ​

When indeterminate is true, a secondary-colored dash is shown; tapping the indeterminate state switches it to checked (golden case indeterminate-becomes-checked). disabled prevents toggling.

9:41Checkbox sizes and disabled

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
checkedWhether checkedbooleanfalse
indeterminateWhether indeterminate; becomes checked after a tapbooleanfalse
disabledWhether disabled; does not fire onChange when disabledbooleanfalse
labelText labelstring''
sizeCheckbox size, maps to the checkbox.size tokensLhCheckboxSizeMedium
onChangeFired on tap with the new checked state(checked: boolean) => voidEmpty function

LhCheckboxSize ​

Valuesize
Smallcheckbox.size.small (16vp)
Mediumcheckbox.size.medium (20vp)
Largecheckbox.size.large (24vp)

Checked state: background color.primary.default, check color.onPrimary, border in the primary color; unchecked state: transparent background, border color.border.base; indeterminate state: a secondary-colored dash; disabled state uses color.disabled.*.

Token reference ​

TokenPurpose
checkbox.size.{small,medium,large}Three sizes
checkbox.borderRadius / checkbox.borderWidthCorner radius and border width (2 / 2vp)
checkbox.checkWidthCheck-mark stroke width
checkbox.gapGap between the box and the label (8vp)
color.primary.default / color.onPrimaryChecked background / check color
color.border.baseUnchecked border color
color.text.secondaryIndeterminate dash color
color.disabled.{bg,text,border}Three disabled-state colors
typography.fontSize.baseLabel font size

Golden case reference ​

How the 6 assertions in cases/checkbox.json map onto hypium tests (entry/src/test/Checkbox.test.ets):

case idAssertionLocal test
tap-toggles-and-emits-onchangeA tap toggles and fires onChangetap_toggles_checked
tap-checked-unchecksTapping the checked state unchecks ittap_checked_unchecks
disabled-blocks-changeDisabled state does not fire onChangedisabled_is_not_interactive
checked-uses-primary-tokensChecked state consumes the primary tokenschecked_uses_primary_tokens
unchecked-uses-border-tokenUnchecked state consumes the border tokenunchecked_uses_border_token
indeterminate-becomes-checkedTapping the indeterminate state checks itindeterminate_becomes_checked / indeterminate_uses_dash_mark

Plus dark-mode specifics: dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode. To run: in DevEco Studio, right-click entry/src/test → Run Tests.

lh-ui native bloodline · HarmonyOS (ArkTS + ArkUI)