useCheckbox

Provides the behavior and accessibility implementation for a checkbox component. Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected.

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

<Checkbox>Unsubscribe</Checkbox>

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>
useToggleState(props: ): useCheckbox( props: , state: , inputRef: <HTMLInputElementnull> ):

ToggleState

Properties

NameType
isSelectedboolean

Whether the toggle is selected.

defaultSelectedboolean

Whether the toggle is selected by default.

Methods

setSelected(isSelected: boolean): void
Updates selection state.
toggle(): void
Toggle the selection state.

AriaCheckboxProps

NameType
isIndeterminateboolean

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

childrenReactNode

The label for the element.

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.

onChange(isSelected: boolean) => void

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

CheckboxAria

NameType
labelPropsLabelHTMLAttributes<HTMLLabelElement>

Props for the label wrapper element.

inputPropsInputHTMLAttributes<HTMLInputElement>

Props for the input element.

descriptionProps<HTMLElement>

Props for the checkbox description element, if any.

errorMessageProps<HTMLElement>

Props for the checkbox error message element, if any.

isSelectedboolean

Whether the checkbox is selected.

isPressedboolean

Whether the checkbox is in a pressed state.

isDisabledboolean

Whether the checkbox is disabled.

isReadOnlyboolean

Whether the checkbox is read only.

validationDetailsValidityState

The native validation details for the input.