Checkbox

A checkbox allows a user to select an item, with support for validation and help text.

Theme 
 
 
isIndeterminate 
isDisabled 
Example
Checkbox.tsx
Checkbox.css
import {Checkbox} from './Checkbox';

<Checkbox>Remember me</Checkbox>

Selection

Use the isSelected or defaultSelected prop to set the selection state, and onChange to handle selection changes. The isIndeterminate prop overrides the selection state regardless of user interaction.

You are unsubscribed

isIndeterminate 
import {Checkbox} from './Checkbox';
import {useState} from 'react';

function Example(props) {
  let [selected, setSelection] = useState(false);

  return (
    <>
      <Checkbox
        {...props}
        isSelected={selected}
        onChange={setSelection}
      >
        Subscribe
      </Checkbox>
      <p>{`You are ${props.isIndeterminate ? 'partially subscribed' : selected ? 'subscribed' : 'unsubscribed'}`}</p>
    </>
  );
}

Forms

Use the name and value props to submit the checkbox to the server. Set the isRequired prop to validate the user selects the checkbox, or implement custom client or server-side validation. See the Forms guide to learn more.

By clicking this checkbox, you agree to the terms and conditions.
import {Checkbox} from './Checkbox';
import {Button} from './Button';
import {Form} from './Form';;

<Form>
  <Checkbox
    name="terms"
    value="agree"
    isRequired
    description="By clicking this checkbox, you agree to the terms and conditions.">
    Accept terms and conditions
  </Checkbox>
  <Button type="submit" style={{marginTop: 8}}>Submit</Button>
</Form>

API

Shows a checkbox component with labels pointing to its parts, including the input, and label elements.SubscribeLabelInput
<CheckboxField>
  <CheckboxButton>Label</CheckboxButton>
  <Text slot="description" />
  <FieldError />
</CheckboxField>

CheckboxField

A checkbox allows a user to select an item, with support for validation and help text.

NameType
inputRef<HTMLInputElementnull>

A ref for the HTML input element.

isIndeterminateboolean

Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction.

defaultSelectedboolean

Whether the element should be selected (uncontrolled).

isSelectedboolean

Whether the element should be selected (controlled).

isDisabledboolean

Whether the input is disabled.

isReadOnlyboolean

Whether the input can be selected but not changed by the user.

children<>

The children of the component. A function may be provided to alter the children based on component state.

onChange(isSelected: boolean) => void

Handler that is called when the element's selection state changes.

Default className: react-aria-CheckboxField

Render PropCSS Selector
isSelectedCSS Selector: [data-selected]
Whether the checkbox is selected.
isIndeterminateCSS Selector: [data-indeterminate]
Whether the checkbox is indeterminate.
isDisabledCSS Selector: [data-disabled]
Whether the checkbox is disabled.
isReadOnlyCSS Selector: [data-readonly]
Whether the checkbox is read only.
isInvalidCSS Selector: [data-invalid]
Whether the checkbox invalid.
isRequiredCSS Selector: [data-required]
Whether the checkbox is required.

CheckboxButton

A checkbox button is the clickable area of a checkbox, including the indicator and label.

NameType
children<>

The children of the component. A function may be provided to alter the children based on component state.

Default className: react-aria-CheckboxButton

Render PropCSS Selector
isSelectedCSS Selector: [data-selected]
Whether the checkbox is selected.
isIndeterminateCSS Selector: [data-indeterminate]
Whether the checkbox is indeterminate.
isHoveredCSS Selector: [data-hovered]
Whether the checkbox is currently hovered with a mouse.
isPressedCSS Selector: [data-pressed]
Whether the checkbox is currently in a pressed state.
isFocusedCSS Selector: [data-focused]
Whether the checkbox is focused, either via a mouse or keyboard.
isFocusVisibleCSS Selector: [data-focus-visible]
Whether the checkbox is keyboard focused.
isDisabledCSS Selector: [data-disabled]
Whether the checkbox is disabled.
isReadOnlyCSS Selector: [data-readonly]
Whether the checkbox is read only.
isInvalidCSS Selector: [data-invalid]
Whether the checkbox invalid.
isRequiredCSS Selector: [data-required]
Whether the checkbox is required.