@akhatmirzo/ui

Checkbox

A checkbox built on the native input, with a label, a description and an indeterminate state.

Import

import { Checkbox } from '@akhatmirzo/ui';

When to use

  • In forms with a "Save" button — the choice takes effect when the form is submitted. For settings that apply immediately, use a Switch.
  • For several independent choices — notification channels, filters. When only one option can be picked, use a RadioGroup.
  • For consent — "I agree to the terms". If it's mandatory, use required and error on a Field.
  • Phrase labels positively: "Send notifications", not "Don't send notifications".

Sizes

sm is 16px and md (default) is 20px. Both have an invisible hit area larger than the box.

With a description

description appears under the label in smaller, muted text and is linked to the input with aria-describedby.

Indeterminate

checked="indeterminate" shows a "−". It's typically used on a "select all" box when only some children are selected. onCheckedChange only reports a boolean — you compute the mixed state yourself.

States

disabled dims the box and label and blocks clicks. invalid turns the border red and sets aria-invalid on the input.

With Field

Field connects the error and hint to the checkbox; when error is set, invalid turns on automatically. Try checking the box.

Davom etish uchun rozilik kerak

Props

Checkbox accepts every other <input> attribute (name, value, form, onChange ...), and ref points to the inner <input>. className goes to the root <label>.

PropTypeDefaultDescription
checkedboolean | 'indeterminate'—Controlled value
defaultCheckedboolean | 'indeterminate'falseInitial value (uncontrolled)
onCheckedChange(checked: boolean) => void—Called when the user checks or unchecks the box
labelReactNode—Text next to the box
descriptionReactNode—Hint under the label
size'sm' | 'md''md'Size: 16 / 20px
invalidboolean—Error state (automatic inside a Field with an error)
disabledboolean—Disabled state
classNamestring—Class for the root <label>

Data attributes

On the root <label>:

AttributeValue
data-statechecked · unchecked · indeterminate
data-sizesm · md
data-disabledPresent when disabled
data-invalidPresent when invalid

Accessibility

  • Native <input type="checkbox"> — toggles with Space, submits with the form like any checkbox, and browser validation (required) works.
  • Clicking the label toggles it too — the whole component is a <label>.
  • The mixed state is announced with aria-checked="mixed".
  • The focus ring shows only for keyboard focus.
  • For a checkbox without a label (say, in a table row), pass aria-label.

On this page