Skip to main content
Brand and assets
Build
Monitor and contribute
/
Component library
  • All components
  • Buttons & actions
  • Forms & inputs
    • Checkbox
    • ChoiceGroup
    • CurrencyInput
    • DateInput
    • FileInputZone
    • Filters
    • Form
    • MaskedTextInput
    • PasswordInput
    • Pill
    • Pill
    • Radio
    • SearchInput
    • SegmentedSlider
    • Select
    • Switch
    • TextArea
    • TextInput
  • Layout & containers
  • Overlays
  • Feedback & status
  • Data display
  • Typography
  • Accessibility
  • Contrib
  • Deprecated
  • Forms & inputs
  • Checkbox

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.

Health
Component health
Source
View on Github
Design
View Figma
Storybook
View in Storybook
Playground
No Example
Accessibility

compliant

Platform
Universal
  • Overview
  • Props
  • Figma

Usage​

States​

Indeterminate state​

Checkbox supports indeterminate state. When indeterminate prop is true, checked prop is ignored.

Error state​

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​

Loading...
tip
This component is universal, its usage is the same in murray and murray/mobile.

Checkbox props

NameTypeDefault ValueDescriptionUsage count
aria-describedbystringundefinedId of an element that describes the input, only necessary if `helpText` is not used and the text is already present in the page
aria-labelstringundefinedAccessibility label, only necessary if `label` is not used
aria-labelledbystringundefinedAccessibility label, only necessary if `label` is not used and the text is already present in the page
autoFocusbooleanundefinedIf true, focuses the input on componentDidMount.The default value is false.
borderWidthSizeTokensundefinedOverride the default 2px border.
checkedbooleanundefinedControl the input.
countnumberundefinedResult 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.
defaultCheckedbooleanundefinedUncontrolled default value.
density"standard""condensed"undefinedOverride the theme-derived density. Use "condensed" to force the 16px size.
disabledbooleanundefinedDisable element
errorReactNodeContents of `InputError` component, if not set, error is not rendered.
helpTextReactNodeContents of `InputHelpTextNext` component, if not set, description is not rendered.
idstringundefinedOverride the default generated id
indeterminatebooleanundefinedIndeterminate state of checkbox, if set, `checked` prop is ignored
labelReactNodeContents of `InputLabelNext` component, if not set, label is not rendered.
namestringundefinedHtml input name
onBlurundefinedFocusEventHandler<HTMLDivElement>Callback that is called when the element is blurred
onChange((value: boolean) => void)undefinedTrigger when the checked state is changing
onFocusundefinedFocusEventHandler<HTMLDivElement>Callback that is called when the element is focused
requiredbooleanundefinedAdds aria-required attribute to the input and a red asterisk on the right side of label, `false` by default
testIDstringundefined
valuestringundefinedGive it a value (for use in HTML forms).

Undocumented props

NameTypeDefault ValueDescriptionUsage count
refany

CheckboxGroup props

NameTypeDefault ValueDescriptionUsage count
aria-labelstringundefined
children*ReactNodeArray of `CheckableNext` eleements
defaultValuestring[]undefinedArray of checked elements (when uncontrolled)
errorReactNodeContents of `InputError` component, if not set, error is not rendered.
helpTextReactNodeContents of `InputHelpTextNext` component, if not set, description is not rendered.
labelReactNode
namestringundefinedHtml inputs name
onBlurundefinedFocusEventHandler<HTMLDivElement>Callback that is called when a child switch is blurred
onChange((value: string[]) => void)undefinedCallback that is called when a child switch state is changing
orientation"vertical""horizontal"undefinedOrientation for the layout (vertical by default)
requiredbooleanundefinedAdds red asterisk on the right side of label, `false` by default
valuestring[]undefinedArray of checked elements (when controlled)
Edit this page
Previous
SemanticButton
Next
ChoiceGroup
  • Usage
  • States
  • Indeterminate state
  • Error state
  • Controlled
  • Condensed theme
  • Checkbox.Group
  • Result count
  • Usage in <Form>
  • Playground