Checkbox
A box to turn one choice on or off, with an indeterminate state.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on radix-ui/Checkbox
- role=checkbox; Space toggles; Tab focuses.
- indeterminate is exposed as aria-checked=mixed.
- A visible label is clickable; without one, aria-label is required.
- Styles in one file:
checkbox.css
Import
import '@monoline/css';
import {Checkbox} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add checkbox
It needs radix-ui; install it if your project does not have it:
npm install radix-ui
Usage
import {Checkbox} from '@monoline/react';
<div style={{display: 'grid', gap: 'var(--s3)'}}>
<Checkbox label="Replies" defaultChecked />
<Checkbox label="Mentions" />
<Checkbox label="Billing (locked)" disabled />
</div>
Examples
Basic
Indeterminate
Props
CheckboxProps
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | – | Visible label. Without it, give the checkbox an `aria-label`. |
invalid | boolean | – | Marks the checkbox as having an error: sets `aria-invalid` and shows the error border. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[aria-invalid="true"] | checkbox.css |
[data-orientation="horizontal"] | checkbox.css |
[data-state="checked"] | checkbox.css |
[data-state="indeterminate"] | checkbox.css |
CSS classes
| Class | Stylesheet |
|---|---|
.checkbox | checkbox.css |
.checkbox-mark | checkbox.css |
.radio | checkbox.css |
.radio-dot | checkbox.css |
.radio-group | checkbox.css |
.sw | checkbox.css |
.sw-thumb | checkbox.css |
.choice | 10-choices.css |
.choice-group | 10-choices.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.checkbox {
border-color: var(--accent);
}
.checkbox[aria-invalid="true"] {
background: var(--wash);
}
Try the props
Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.
example.tsx
<Checkbox label="Email me updates" />
Accessibility
- role=checkbox; Space toggles; Tab focuses.
- indeterminate is exposed as aria-checked=mixed.
- A visible label is clickable; without one, aria-label is required.
Keyboard
| Keys | Action |
|---|---|
| Space | Toggles |
| Tab | Focuses |