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.
import {Checkbox} from './Checkbox';
<Checkbox>Unsubscribe</Checkbox>
API
<CheckboxField>
<CheckboxButton>Label</CheckboxButton>
<Text slot="description" />
<FieldError />
</CheckboxField>
useToggleState (props: ToggleStateOptions ): ToggleStateuseCheckbox(
props: AriaCheckboxProps,
state: ToggleState,
inputRef: RefObject <HTMLInputElement | null >
): CheckboxAriaToggleState
Properties
| Name | Type | |
|---|---|---|
isSelected | boolean | |
Whether the toggle is selected. | ||
defaultSelected | boolean | |
Whether the toggle is selected by default. | ||
Methods
setSelected | ||
| Updates selection state. | ||
toggle | ||
| Toggle the selection state. | ||
AriaCheckboxProps
| Name | Type | |
|---|---|---|
isIndeterminate | boolean | |
Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction. | ||
children | ReactNode | |
The label for the element. | ||
defaultSelected | boolean | |
Whether the element should be selected (uncontrolled). | ||
isSelected | boolean | |
Whether the element should be selected (controlled). | ||
isDisabled | boolean | |
Whether the input is disabled. | ||
isReadOnly | boolean | |
Whether the input can be selected but not changed by the user. | ||
onChange | | |
Handler that is called when the element's selection state changes. | ||
CheckboxAria
| Name | Type | |
|---|---|---|
labelProps | LabelHTMLAttributes | |
Props for the label wrapper element. | ||
inputProps | InputHTMLAttributes | |
Props for the input element. | ||
descriptionProps | | |
Props for the checkbox description element, if any. | ||
errorMessageProps | DOMAttributesWithRef | |
Props for the checkbox error message element, if any. | ||
isSelected | boolean | |
Whether the checkbox is selected. | ||
isPressed | boolean | |
Whether the checkbox is in a pressed state. | ||
isDisabled | boolean | |
Whether the checkbox is disabled. | ||
isReadOnly | boolean | |
Whether the checkbox is read only. | ||
validationDetails | ValidityState | |
The native validation details for the input. | ||