CxJS

Checkbox

import { Checkbox } from 'cx/widgets'; Copied

The Checkbox widget is used for expressing binary choices. It supports both standard styled checkboxes and native HTML checkboxes.

<LabelsTopLayout columns={2}>
  <Checkbox
    label="Standard"
    value={bind(m.checked, true)}
    text="I agree to terms"
  />
  <Checkbox label="Native" value={m.checked} text="I agree to terms" native />
  <Checkbox
    label="Disabled"
    value={m.checked}
    text="I agree to terms"
    disabled
  />
  <Checkbox
    label="Read-only"
    value={m.checked}
    text="I agree to terms"
    readOnly
  />
  <Checkbox
    label="Required"
    value={m.checked}
    text="I agree to terms"
    required
  />
  <Checkbox
    label="Three State"
    value={m.indeterminate}
    text="Select all"
    indeterminate
  />
</LabelsTopLayout>

Three State Mode

Use the indeterminate prop to enable three-state mode. This displays a square icon when the value is null or undefined, which is useful for “select all” scenarios where only some items are selected.

Configuration

Core Properties

PropertyTypeDefaultDescription
valuebooleanfalseChecked state of the checkbox
checkedbooleanAlias for value
textstringText displayed next to the checkbox
labelstringLabel displayed before the checkbox
disabledbooleanfalseDisables the checkbox
readOnlybooleanfalseMakes the checkbox read-only
requiredbooleanfalseRequires the checkbox to be checked
indeterminatebooleanfalseEnables three-state mode (checked, unchecked, indeterminate)
viewModebooleanfalseDisplay as plain text instead of interactive checkbox
autoFocusbooleanfalseAutomatically focus the field on mount

Appearance

PropertyTypeDefaultDescription
nativebooleanfalseUse native HTML checkbox instead of styled version
inputStyleobjectCSS styles for the checkbox element
viewTextstringText displayed in view mode
emptyTextstringText shown in view mode when value is empty
tooltipstringTooltip text or configuration

Behavior

PropertyTypeDefaultDescription
unfocusablebooleanfalseDisable focusing on the checkbox (useful in grids)

Callbacks

PropertyTypeDescription
onValidatefunctionCustom validation function returning error message or undefined