Checkbox
One or more independent choices, read back as a set and submitted with the form.
Umbrella
The portable contract both renderers implement.
Install
npm install asheeui @asheeui/webImport
import { Checkbox } from "asheeui";The same props and the same cascade as the web; the implementation is the platform's.
One contract and a real implementation on both platforms.
The umbrella is the intersection; see the portable surface for the complete list and the monorepo guide for wiring one shared kit to both applications.
The live examples below run the web branch in this browser. The umbrella is the contract both branches implement; open Web for the browser's extra APIs and Native for the device's behaviour.
A checkbox holds a boolean a form submits later. That is what separates it from a switch: a switch is a setting that takes effect now, while a checkbox is a value the reader chooses and the form sends when it is submitted.
CheckboxGroup is the field. It carries the label, the description, the message and the
status, and it owns a string[]: the values currently ticked. Checkbox is one option
inside it, receiving the group's name, selection, tokens and disabled state through
context. A Checkbox outside a group keeps its own checked or defaultChecked state,
which is what makes a single consent line possible.
Usage
import { Checkbox, CheckboxGroup } from "asheeui";
<CheckboxGroup label="Interests" defaultValue={["news"]}>
<Checkbox value="news" label="News" />
<Checkbox value="sport" label="Sport" />
</CheckboxGroup>
An uncontrolled group keeps the set itself, which is enough while nothing else on the
page needs it. Pass value and onChange when the selection has to live with the rest
of the form, so the group reports the whole set and the consumer decides what it means:
<CheckboxGroup label="Interests" value={interests} onChange={setInterests}>
<Checkbox value="news" label="News" />
<Checkbox value="sport" label="Sport" />
</CheckboxGroup>
Each option needs a value, which identifies it in the group and is the value a form
submits. Its onChange receives the next checked state, the option's value and the
change event. A standalone checkbox uses the same handler, and checked or
defaultChecked in place of the group's set:
<Checkbox
value="terms"
label="I accept the terms"
checked={accepted}
onChange={(checked) => setAccepted(checked)}
/>
Groups
The group is one field, so its label, description and message are stated once and every
option inherits size, color, status and disabled. An option's own prop wins over
the group's, and name is shared by every checkbox in the group so a native form
submits them under one key.
orientation defaults to vertical, a column of options. Set it to horizontal for
short labels that read as one question; a column is better when an option needs a
description underneath it, because the descriptions then line up instead of competing for
the same row.
States
status on the group paints the unchecked squares and gives the message its tone; a
checked box takes the accent colour instead. disabled on an option keeps its label and
description in the reading order but takes it out of reach, and disabled on the group
does the same for every option.
A checkbox outside a group takes the same status, size, color and radius props as
one inside it. It has no message of its own, so what the reader needs to know belongs in
description.
Props
The group's table is the one to read for the field. Its value or defaultValue is the
set and its onChange reports the next set. required marks the group's label; because
the group has no single control to receive the attribute, state the rule in the
description or the message as well.
An option needs a value and a label. Everything else it renders — its density, accent,
rounding and validation edge — arrives from the group unless the option states its own,
and the option's own prop wins.
Registered defaults belong to the component rather than to the application:
components.checkbox states size: "md" and radius: "sm", so a checkbox stays a
square rather than taking the application's default rounding. color is not registered,
so it follows defaultColor, and status follows default.
Accessibility
- The group is a
fieldset, the native group for a set of controls. Its visible label names it througharia-labelledby, and the description and message are referenced witharia-describedby; the label is not attached to any one input, because none of them is the field. - Each option is a real
<input type="checkbox">inside its own<label>, so the visible text is the option's name and the checked state is the browser's. Space toggles the focused option, and the input sits in the tab order without atabindex. - The square and the check are decoration drawn from the input's state, and the focus ring
is drawn from
focus-visibleon that square, so it appears for a keyboard and not for a pointer. An option'sdescriptionsits inside the same label, so it is read with the option. disabledon an option takes it out of the tab order; on the group it takes every option with it while the labels stay readable.requiredon a standalone checkbox reaches its input; on a group it marks the label only, which is why the rule belongs in the description or the message too.- On a device the option is a
PressablewithaccessibilityRole="checkbox"andaccessibilityState, and the group is arole="group"view with its label as the group's name.
The label, description and message behave as the field anatomy describes.