Checkbox
A checkbox with its check mark built in.
Wrap a checkbox and its text in a Label, so a press on the text toggles it.
Dependencies
What it's built from and what's built from it in Mocha, read from the imports in its source.
| Uses | Nothing else in the system. |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20lucide-react@1.73.0 |
Installation
Set the project up for Mocha once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Then copy the source:
API reference
Generated from Mocha's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
Checkbox
A checkbox with its check mark built in. Pass children to replace the indicator. Wrap it in a Label with its text, or name it with aria-label.
- checked
Whether it's checked. Pass it to control the checkbox.
Type CheckedState
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: CheckboxState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: CheckboxState) => string)
- controller
Toggles it from anywhere. Create one with
createCheckboxController().Type { toggle: (details?: CheckboxChangeOptions) => boolean; getChecked: () => CheckedState; setChecked: (checked: CheckedState, details?: CheckboxChangeOptions) => boolean; focus: () => void; }
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultChecked
Whether it's checked at first, when uncontrolled. A form reset returns to it.
Type CheckedState · Default false
- disabled
Disables it like a native control: it can't be focused or changed, and isn't submitted.
Type boolean
- form
The id of a form to belong to, when it isn't inside that form.
Type string
- name
The name it submits under. Without one, it submits nothing.
Type string
- onCheckedChange
Runs when a user or a form reset wants to change it.
details.reasonsays why, anddetails.cancel()stops it.Type (checked: CheckedState, details: ChangeDetails<CheckboxCheckedChangeReason>) => void
- parent
Makes it the parent of its group: it checks or unchecks every checkbox in the group, and shows checked, unchecked or indeterminate from them.
Type boolean · Default false
- readOnly
Keeps it focusable and submitted, but stops changes.
Type boolean
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<CheckboxState>
- required
Blocks form submission until it's checked, with the browser's own message.
Type boolean
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: CheckboxState) => CSSProperties)
- value
What it submits while checked.
Type string · Default "on"
CheckboxIndicator
Shows the check mark, or a dash while the checkbox is indeterminate.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: NoInfer<CheckboxState>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: NoInfer<CheckboxState>) => string)
- keepMounted
Whether the indicator stays in the page while unchecked, so it can be styled or animated in both states.
Type boolean · Default false
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<NoInfer<CheckboxState>>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: NoInfer<CheckboxState>) => CSSProperties)