Checkbox
An easily stylable checkbox component.
API reference
Import the component and place its parts the following way:
import { Checkbox } from '@base-ui-components/react/checkbox';
<Checkbox.Root>
<Checkbox.Indicator />
</Checkbox.Root>
Root
Represents the checkbox itself.
Renders a <button>
element and a hidden <input>
beside.
Prop | Type | Default | |
---|---|---|---|
checked | boolean | undefined | |
className | string | (state) => string | undefined | |
defaultChecked | boolean | false | |
disabled | boolean | false | |
indeterminate | boolean | false | |
inputRef | React.Ref | undefined | |
name | string | undefined | |
onCheckedChange | (checked, event) => void | undefined | |
parent | boolean | false | |
readOnly | boolean | false | |
render | | React.ReactElement | undefined | |
required | boolean | false |
Attribute | Description | |
---|---|---|
data-checked | Present when the checkbox is checked. | |
data-dirty | Present when the checkbox's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the checkbox is disabled. | |
data-invalid | Present when the checkbox is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the checkbox is readonly. | |
data-required | Present when the checkbox is required. | |
data-touched | Present when the checkbox has been touched (when wrapped in Field.Root). | |
data-unchecked | Present when the checkbox is not checked. | |
data-valid | Present when the checkbox is in valid state (when wrapped in Field.Root).. |
Indicator
Indicates whether the checkbox is ticked.
Renders a <span>
element.
Prop | Type | Default | |
---|---|---|---|
className | string | (state) => string | undefined | |
keepMounted | boolean | false | |
render | | React.ReactElement | undefined |
Attribute | Description | |
---|---|---|
data-checked | Present when the checkbox is checked. | |
data-dirty | Present when the checkbox's value has changed (when wrapped in Field.Root). | |
data-disabled | Present when the checkbox is disabled. | |
data-ending-style | Present when the checkbox indicator is animating out. | |
data-invalid | Present when the checkbox is in invalid state (when wrapped in Field.Root). | |
data-readonly | Present when the checkbox is readonly. | |
data-required | Present when the checkbox is required. | |
data-starting-style | Present when the checkbox indicator is animating in. | |
data-touched | Present when the checkbox has been touched (when wrapped in Field.Root). | |
data-unchecked | Present when the checkbox is not checked. | |
data-valid | Present when the checkbox is in valid state (when wrapped in Field.Root). |