Skip to main content

Checkbox

A simple boolean input. Can be combined with other checkboxes to create lists of options.

Examples

Plain Checkbox

A box that displays a checkmark when selected. An indeterminate checkbox indicates that a box is in an incomplete state.

import { Checkbox } from '@curology/ui-components-web/react/Checkbox';

<Checkbox
size="{sm|md(default)}"
checked
indeterminate
/>

With label

A label can (and should!) be added to each checkbox to indicate its purpose. It can also have additional meta text applied beneath.

import { Checkbox } from '@curology/ui-components-web/react/Checkbox';

<Checkbox
...
label="A checkbox with a label"
meta="And some meta text"
/>

Critical, Warning, Success, and Disabled States

There are four additional states the Checkbox can be in, to indicate danger, warning, success or the inability to be controlled.

import { Checkbox } from '@curology/ui-components-web/react/Checkbox';

<Checkbox
state="{''(default)|critical|warning|success}"
/>

With children

Nested content can be added below the checkbox. If alwaysShowChildren is true, the child content will display even if the checkbox is unselected.

Child content only visible when checked.

Child content only visible when checked.

Child content always visible.

Child content always visible.

import { Checkbox } from '@curology/ui-components-web/react/Checkbox';

<Checkbox
...
alwaysShowChildren
/>

Controlled Checkbox

Like all form inputs, a Checkbox can either be uncontrolled, or controlled (by providing a value and onChange listener).

import { Checkbox } from '@curology/ui-components-web/react/Checkbox';

<Checkbox
size="{sm|md(default)}"
checked
indeterminate
onChange={(evt, checked) => ...}
/>

As a list

A list of checkboxes, complete with a label and helperText at the top, can be displayed by wrapping multiple Checkboxes in a CheckboxGroup.

import { Checkbox } from '@curology/ui-components-web/react/Checkbox';
import { CheckboxGroup } from '@curology/ui-components-web/react/CheckboxGroup';

<CheckboxGroup
name="labeled"
values={['a']}
label="A list of radio choices"
helperText="Just pick one"
onChange={(evt, values) => ...}
>
<Checkbox value="a" />
<Checkbox value="b" />
<Checkbox value="c" />
</CheckboxGroup>

Props

CheckboxProps

NameTypeDefault ValueRequiredDescription
All attributes of a <input />
alwaysShowChildrenfalse | truefalseNoShould the children display even if `checked=false`?
indeterminatefalse | truefalseNoShow a partially selected checkbox when `checked=true`.
labelReactNodeNoA string or component to display as a label above the input
metaReactNodeNoA string or component to display as meta text beneath the input
onChangeFormControlChangeEventHandlerNoEmit a new value when the input's selected value changes.
size"md" | "sm"'md'NoThe size of the field
state"" | "critical" | "warning" | "success"''NoThe state of the field
type"checkbox" | "radio"checkboxNoShould this render/behave as a checkbox or radio button?

CheckboxGroupProps

NameTypeDefault ValueRequiredDescription
All attributes of a <div />
brand"agency" | "curology"''NoThe brand of the component.
defaultValuestring | number | readonly string[] | (string | number | readonly string[] | undefined)[]NoDefault value to use the first time the context is created.
disabledfalse | truefalseNoShould the field be considered disabled?
fieldClassNamestringNoA className to apply to the field.
fieldPropsRecord<string, unknown>NoAny props to spread onto the field container.
helperTextReactNodeNoA string or component to display as helper text beneath the input
highlightReactNodeNoHighlighted helper text to display at the bottom of the multiline text input
highlightClassNamestringNoA className to apply to the highlight.
idstring''NoA unique ID for this form control.
labelReactNodeNoA string or component to display as a label above the input
namestring''NoThe name for the radio group.
onChange(evt: ChangeEvent<HTMLInputElement>, value: (string | number | readonly string[] | undefined)[]) => voidNoEmit a new value when the group's selected values change.
requiredfalse | truefalseNoIs the field required?
resizefalse | truefalseNoEnable or disable resizing.
size"md" | "sm"'md'NoThe size of the field.
state"" | "critical" | "warning" | "success"''NoThe state of the field
type"number" | "image" | "search" | "button" | "time" | "text" | "color" | "hidden" | string & {} | "submit" | "reset" | "checkbox" | "date" | "datetime-local" | "email" | "file" | "month" | "password" | "radio" | "range" | "tel" | "url" | "week"'text'NoThe type of the input.
valuestring | number | readonly string[] | (string | number | readonly string[] | undefined)[]''NoThe currently selected value.
valuesstring | string[][]NoA list of selected values.