A single checkbox empowers users to select multiple items from a list of individual options or mark one individual item as selected, offering the flexibility to choose one or more items from a range of choices.
Features
Checkbox is automatically connected to handle Accessibility features. Checkbox has some features baked in to make it easier to use and more consistent.
- Built with a native
<input>element - Visual and ARIA labeling support
- Required and invalid states exposed to assistive technology via ARIA
- Support for description and error message help text linked to the input via ARIA
- Easily customize appearance by hiding the HTML
<input>for full styling control.
Usage
import { Checkbox } from '@console/nimbus-ui/core';Examples
Indeterminate
A Checkbox can be in an indeterminate state, controlled using the indeterminate prop.
This overrides the appearance of the Checkbox, whether selection is controlled or uncontrolled.
The Checkbox will visually remain indeterminate until the indeterminate prop is set to false,
regardless of user interaction.
Read Only
Pass the readonly prop to checkbox when the user should not be able to toggle the checkbox but be able to focus the checkbox.
Disabled
Pass the disabled prop to checkbox when the user should not be able to toggle the checkbox and not be able to focus the checkbox.
Invalid
Pass the invalid prop to the checkbox to place the checkbox in its invalid state
Controlled
The isSelected prop can be used to make the selected state controlled.
The onChange event is fired when the user presses the checkbox, and receives the new value.
Default Selected
Pass the defaultSelected prop to toggle on default selected (uncontrolled).
If you're using a controlled version of the checkbox, use the selected prop.
Auto Focus
Pass the autofocus prop to automatically toggle focus. This is commonly used within modals or popovers to not focus trap the user.
No Label
Do not pass a child to the checkbox if you do not want a label. Cannot render a hint if a label is not rendered
An aria-label prop must be specified when the checkbox is used with no label, for accessibility.
With Hint
Pass the hint prop to render a hint with the label. The hint will not be rendered if there is no label.
Rich Content
Children are a composable prop you can use to create rich content for the checkbox.
API
| Prop | Type | Default | Description |
|---|---|---|---|
| classes | { root?: string; indicator?: string; labelContainer?: string; label?: string; hint?: string; } | — | |
| data-testid | string | — | id for E2E testing purposes |
| disabled | boolean | — | Whether the checkbox is disabled. @selector [data-disabled] |
| hint | ReactNode | — | |
| indeterminate | boolean | — | Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction. @selector [data-indeterminate] |
| invalid | boolean | — | Whether the checkbox is in an invalid state @selector [data-invalid] |
| readonly | boolean | — | Whether the checkbox can be selected but not changed by the user. @selector [data-readonly] |
React Aria
Figma