Checkbox
An easily stylable checkbox component.
API reference
Import the component and place its parts the following way:
Anatomy
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 | Type | |
---|---|---|
data-checked | Empty attribute | |
data-dirty | Empty attribute | |
data-disabled | Empty attribute | |
data-invalid | Empty attribute | |
data-readonly | Empty attribute | |
data-required | Empty attribute | |
data-touched | Empty attribute | |
data-unchecked | Empty attribute | |
data-valid | Empty attribute |
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 | Type | |
---|---|---|
data-checked | Empty attribute | |
data-dirty | Empty attribute | |
data-disabled | Empty attribute | |
data-ending-style | Empty attribute | |
data-invalid | Empty attribute | |
data-readonly | Empty attribute | |
data-required | Empty attribute | |
data-starting-style | Empty attribute | |
data-touched | Empty attribute | |
data-unchecked | Empty attribute | |
data-valid | Empty attribute |