Skip to content
SENVENLI UI

Checkbox

A box to turn one option on or off, or a group of boxes for several options.
One option
import { Checkbox, CheckboxGroup } from "@senvenli/react/selection";

Examples

A group

Several options under one legend.

Indeterminate parent

A parent box shows a minus while only some of its options are checked.

Invalid and disabled

The error sits under the label; disabled options keep their value.

Sizes

`size` small, medium (default) or large; a CheckboxGroup sets it for its boxes.

Guidelines

When to use it

  • Agreeing to something, or choosing several options from a few.

Use something else when

  • The setting applies at once. Switch

Do and avoid

  • Write the option positively: "Send notifications", not "Don't send…".

Accessibility

Keyboard

KeysWhat happens
SpaceToggles the box.

Built in

  • Required fields show "Fill in this field." after a blur or a submit; your own errorMessage replaces it.

You provide

  • A label for each box and a legend for the group.

API reference

Checkbox

size
ComponentSize

small, medium (default) or large; a group's size, then the provider default, otherwise.

childrenRequired
React.ReactNode

The option, written positively ("Send notifications").

isSelected
boolean
defaultSelected
boolean
isIndeterminate
boolean

A parent of a partially selected list; shows a minus, never a check.

onChange
(isSelected: boolean) => void
description
React.ReactNode
isInvalid
boolean
errorMessage
React.ReactNode

Shown under the label while the checkbox is invalid (isInvalid or failed native validation).

isDisabled
boolean
isRequired
boolean

The box must be checked (terms to accept); inside a CheckboxGroup the group's isRequired applies instead.

requiredValidation
RequiredValidation

Who says a required box left unchecked is missing: field (default) shows "Fill in this field." on blur and on a DS Form submit, which it then blocks; app only marks it. See {@link RequiredValidation}. The app's isInvalid (true with its errorMessage, or false) overrides the check, as on TextField. Disabled, empty and required, it still blocks a DS Form's submit and cannot take focus (as TextField).

validationBehavior
"aria" | "native"

aria or native; unset, it follows the surrounding form, else React Aria's default (native).

value
string

The value inside a CheckboxGroup.

name
string

CheckboxGroup

size
ComponentSize

The size of every Checkbox in the group.

labelRequired
React.ReactNode

The visible legend, required.

description
React.ReactNode
errorMessage
React.ReactNode
orientation
"horizontal" | "vertical"Default "vertical"
childrenRequired
React.ReactNode
requiredValidation
RequiredValidation

Who says a required group with nothing checked is missing: field (default) shows "Fill in this field." when focus leaves the group and on a DS Form submit, which it then blocks; app only marks the group. See {@link RequiredValidation}. The app's isInvalid (true with its errorMessage, or false) overrides the check, as on TextField. Disabled, empty and required, it still blocks a DS Form's submit and cannot take focus (as TextField).

Also takes 78 standard DOM and ARIA attributes (id, aria-label, event handlers…).