Checkbox
Checkbox
component allows users to create a checkbox to represent boolean states.Basic usage
Checkbox
using its component state.tsxCopied1<Checkbox id="checkbox" label="Click me!" />2<Text>Checked: {String(checkboxState.checked)}</Text>
Disabling
Checkbox
can be disabled using the defaultDisabled
prop.tsxCopied1<Checkbox label="Disabled checkbox" defaultDisabled defaultChecked />
Setting values
setChecked
and setDisabled
functions on the state.tsxCopied1<Button onClick={() => checkboxState.setChecked(!checkboxState.checked)}>2Toggle checked3</Button>4<Button onClick={() => checkboxState.setDisabled(!checkboxState.disabled)}>5Toggle disabled6</Button>7<Checkbox id="checkbox" label="You can control this checkbox using the above buttons" />
Component API
Whether the checkbox is checked when using as a controlled component. Prefer using defaultChecked and the global component state.
Color of the checkbox.
Whether the checkbox is initially checked.
Whether the checkbox is initially disabled.
Description displayed below the checkbox. This can be a string or a React component.
Displays error message after the select input. Can be a string or a React component.
The ID referenced by the global component state.
If true, the checkbox is in an indeterminate state.
Checkbox label. This can be a string or a React component.
Callback when checked state changes when using as a controlled component. Prefer using the global component state.
The border-radius of the checkbox.
Adds red asterisk on the right side of label and sets required on input element
Size of the checkbox.
A single function or an array of functions that validate the input value.
State API
Whether the checkbox is checked
Whether the checkbox is disabled
Sets the value of the checkbox
Sets the disabled value of the checkbox. If the disabled
value is not provided, the checkbox will be disabled