Checkbox
Runs the real component in your browser.
Multiple selection and confirm-style toggles, with a mixed state. Use CheckBox for the box alone, and CheckRow for a fully clickable row with text; both call back with onChange(checked).
Status: stable · Components: CheckBox, CheckRow, CheckMark
Import
Section titled “Import”import { CheckBox, CheckRow, CheckMark } from 'nacre'import { signal } from 'nsh'import { CheckRow } from 'nacre'
export function CheckboxUsage() { const notify = signal(true) return <CheckRow label="Also notify collaborators" checked={notify()} onChange={(checked) => notify.set(checked)} />}Examples
Section titled “Examples”States
Section titled “States”Checked, unchecked, mixed and disabled. CheckBox is only the box; its label is for screen readers only.
import { View, signal } from 'nsh'import { CheckBox } from 'nacre'
export function CheckboxStates() { const on = signal(true) const off = signal(false) return ( <View class="flex-row items-center gap-4"> <CheckBox label="Checked" checked={on()} onChange={(v) => on.set(v)} /> <CheckBox label="Unchecked" checked={off()} onChange={(v) => off.set(v)} /> <CheckBox label="Mixed" checked={false} mixed onChange={() => {}} /> <CheckBox label="Disabled" checked disabled onChange={() => {}} /> </View> )}Select all and mixed
Section titled “Select all and mixed”The parent follows its children: all checked, none checked, or some checked (mixed); clicking the parent checks or clears them all.
import { View, signal } from 'nsh'import { CheckRow } from 'nacre'
const teams = () => ['Hong Kong team', 'Singapore team', 'High-net-worth line']
export function CheckboxIndeterminate() { const TEAMS = teams() const picked = signal<string[]>([TEAMS[0]]) const all = () => picked().length === TEAMS.length const some = () => picked().length > 0 && !all() const toggle = (team: string, on: boolean) => picked.update((list) => (on ? [...list, team] : list.filter((t) => t !== team))) return ( <View class="w-[240px] max-w-full gap-1"> <CheckRow label="All teams" checked={all()} mixed={some()} onChange={(on) => picked.set(on ? [...TEAMS] : [])} /> <View class="pl-6 gap-1"> {TEAMS.map((team) => ( <CheckRow label={team} checked={picked().includes(team)} onChange={(on) => toggle(team, on)} /> ))} </View> </View> )}Full rows
Section titled “Full rows”The whole CheckRow is clickable, and its text is the screen reader name; good for settings and filter lists.
import { View, signal } from 'nsh'import { CheckRow } from 'nacre'
export function CheckboxRows() { const sound = signal(true) const badge = signal(false) return ( <View class="w-[260px] max-w-full gap-1"> <CheckRow label="Play a sound for new messages" checked={sound()} onChange={(v) => sound.set(v)} /> <CheckRow label="Show unread count in the Dock" checked={badge()} onChange={(v) => badge.set(v)} /> <CheckRow label="Set by your administrator" checked={false} disabled onChange={() => {}} /> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Focus |
| Space | Toggle the check |
Accessibility
Section titled “Accessibility”- The role is checkbox, and the state reads as checked / unchecked / mixed.
- CheckBox requires label (the screen reader name); CheckRow’s text is its screen reader name.
- Disabled items are not in the Tab order.
Do / Don’t
Section titled “Do / Don’t”Do
- Use checkboxes for multiple selection, or settings that take effect only after confirming
- Give a group of related items a select-all parent (mixed)
Don’t
- Use a checkbox for a toggle that takes effect immediately (use Switch)
- Use checkboxes for mutually exclusive options (use Radio)
Property descriptions follow the Chinese source comments.
CheckBox
Section titled “CheckBox”| Prop | Type | Default | Description |
|---|---|---|---|
checked * |
boolean |
— | |
mixed |
boolean |
— | 半选(全选列表头、树的父节点):画横杠,读屏报 mixed;点一下的去向由 onChange 决定 |
disabled |
boolean |
— | |
label * |
string |
— | 读屏名(框旁没有可见文字,必须给) |
onChange * |
(checked: boolean) => void |
— | 回调与勾选家族一致:拿到点击后应有的新值(!checked;半选时为 true) |
testID |
string |
— |
* required
CheckRow
Section titled “CheckRow”| Prop | Type | Default | Description |
|---|---|---|---|
checked * |
boolean |
— | |
mixed |
boolean |
— | 半选(父项部分子项勾选):画横杠,读屏报 mixed |
label * |
string |
— | |
onChange * |
(checked: boolean) => void |
— | |
disabled |
boolean |
— | |
testID |
string |
— | |
class |
string |
— | |
children |
JSX.Element |
— | 文字之外的内容(说明、标签);不给就只有 label |
* required
CheckMark
Section titled “CheckMark”| Prop | Type | Default | Description |
|---|---|---|---|
checked * |
boolean |
— | |
mixed |
boolean |
— |
* required