Components · Inputs
Checkbox
A square box for a yes or no that is saved with a form, or an option attached to an action.
import { Checkbox } from "@botiverse/raft-ui";A checkbox is a yes or no that takes effect when the form is saved. Checked, it is an ink block with the check mark knocked out of it: it shows a value, not "you are here", so it is never yellow.
When to use
Which controls apply at once and which are saved is in Forms.
Anatomy
Checkbox: the 20px box, with a hidden native input that holds the state. Required.- A label: wrap the checkbox and its text in a
<label>(Label, orFieldItemwithFieldLabelin a Field). Make the<label>a flex row withgap-2and the label's type: the box takes a box one line of the label tall, so it centers on the text's line by itself, on the first line withitems-start(use it when the label can wrap) and on the one line withitems-centerat any min-height. Don't add amargin-top(Alignment). CheckboxIndicator: the box drawn on its own, with no input or role, for a row or menu item that already has checkbox semantics.
States
The checked, disabled and focus looks follow States.
- Unchecked: an empty box with an ink border.
- Checked: an ink block with the check mark knocked out.
- Indeterminate: an ink block with a minus, for a box that stands for a group whose items are partly checked.
Behavior
- Make the whole label clickable, not only the box. In a
<label>row the box's hit area reaches 4px past its line, half the 8px gap to the next option, so a tap between two lands on the nearer. On its own it is 44 × 44 on a touch screen and 44 × 36 with a mouse.
Content
- Set the label in
text-calloutat weight 600. - In a form, add a line below the label that says what happens when the box is left unchecked.
Accessibility
Checkbox wraps Base UI Checkbox. Its hidden native input drives the checked, disabled and focus state, and the focus ring is drawn on the box (States).
- Give every checkbox a name: a wrapping
<label>, aFieldLabel, oraria-labelwhen there is no visible text (selecting a row). CheckboxIndicatorisaria-hidden. The element that holds it must carry the role and the checked state.
Rules
- Keep the box square. Don't use
shape="circle": round is only for switches, radios and grab handles, and for two exceptions (Shape). The one roundCheckboxIndicatoris a task's completion control, one of those exceptions (Completing a task).
API
Checkbox
Also takes the attributes of its element.
CheckboxIndicator
Also takes the attributes of its element.
Related
Changes
- 0.6.0 · Breaking ChangesProps that no longer change anything are removed:
Badgeuppercase;Checkboxsize,variant,color;Statuspulse,attention(status never animates);Switch/SwitchThumbsize;SidebarItemvariant;SidebarItemCount/SidebarItemIndicatorvariantandappearance(the count is always the pink sticker, the indicator the yellow @);NotificationCenterActionButtonvariant;DrawerContentwidth(one-go forms use the wideDialog);AppRailItemIndicatorattention;AppRailItemAttentionchildren;Stepssize,track,renderIndicator,renderTraveler;FilePreviewBadgetype,color. Remove them at call sites. - 0.6.0 · Added
CheckboxIndicator: the 20px checkbox box as a visual part for picker rows.