Checkbox
Selects one or more options from a list. Supports an indeterminate state for a partly-selected group. It selects; it does not switch something on.
compliant
- Overview
- Props
- Figma
Usage
Help text
States
Indeterminate state
Checkbox supports indeterminate state. When indeterminate prop is true, checked prop is ignored.
Error state
This is an error
Controlled
import { useState } from "react";
import { Checkbox } from "murray";
function Demo() {
const [checked, setChecked] = useState(false);
return <Checkbox checked={checked} onChange={(value) => setChecked(value)} />;
}
Condensed theme
For applications with condensed theme density, this component renders in a condensed style:
Checkbox.Group
It's possible to control several related checkboxes by wrapping them in a Checkbox.Group component:
Result count
Use count to show how many results an option matches, e.g. in a filter. It renders in parentheses after
the label, in a muted style, and is excluded from the accessible label. 0 is displayed as (0): an option
matching nothing keeps its count instead of silently losing it.
Usage in <Form>
On web, Checkbox and CheckboxGroupNext can be used in <Form> component and be controleld by Formik:
Playground
murray and murray/mobile.Checkbox props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-describedby | stringundefined | Id of an element that describes the input, only necessary if `helpText` is not used and the text is already present in the page | ||
| aria-label | stringundefined | Accessibility label, only necessary if `label` is not used | ||
| aria-labelledby | stringundefined | Accessibility label, only necessary if `label` is not used and the text is already present in the page | ||
| autoFocus | booleanundefined | If true, focuses the input on componentDidMount.The default value is false. | ||
| borderWidth | SizeTokensundefined | Override the default 2px border. | ||
| checked | booleanundefined | Control the input. | ||
| count | numberundefined | Result count displayed in parentheses after the label, e.g. `Exempted (12)`. `0` is displayed too. Requires `label`, and is not part of the accessible label. | ||
| defaultChecked | booleanundefined | Uncontrolled default value. | ||
| density | "standard""condensed"undefined | Override the theme-derived density. Use "condensed" to force the 16px size. | ||
| disabled | booleanundefined | Disable element | ||
| error | ReactNode | Contents of `InputError` component, if not set, error is not rendered. | ||
| helpText | ReactNode | Contents of `InputHelpTextNext` component, if not set, description is not rendered. | ||
| id | stringundefined | Override the default generated id | ||
| indeterminate | booleanundefined | Indeterminate state of checkbox, if set, `checked` prop is ignored | ||
| label | ReactNode | Contents of `InputLabelNext` component, if not set, label is not rendered. | ||
| name | stringundefined | Html input name | ||
| onBlur | undefinedFocusEventHandler<HTMLDivElement> | Callback that is called when the element is blurred | ||
| onChange | ((value: boolean) => void)undefined | Trigger when the checked state is changing | ||
| onFocus | undefinedFocusEventHandler<HTMLDivElement> | Callback that is called when the element is focused | ||
| required | booleanundefined | Adds aria-required attribute to the input and a red asterisk on the right side of label, `false` by default | ||
| testID | stringundefined | |||
| value | stringundefined | Give it a value (for use in HTML forms). |
Undocumented props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| ref | any |
CheckboxGroup props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-label | stringundefined | |||
| children* | ReactNode | Array of `CheckableNext` eleements | ||
| defaultValue | string[]undefined | Array of checked elements (when uncontrolled) | ||
| error | ReactNode | Contents of `InputError` component, if not set, error is not rendered. | ||
| helpText | ReactNode | Contents of `InputHelpTextNext` component, if not set, description is not rendered. | ||
| label | ReactNode | |||
| name | stringundefined | Html inputs name | ||
| onBlur | undefinedFocusEventHandler<HTMLDivElement> | Callback that is called when a child switch is blurred | ||
| onChange | ((value: string[]) => void)undefined | Callback that is called when a child switch state is changing | ||
| orientation | "vertical""horizontal"undefined | Orientation for the layout (vertical by default) | ||
| required | booleanundefined | Adds red asterisk on the right side of label, `false` by default | ||
| value | string[]undefined | Array of checked elements (when controlled) |