Skip to main content
cngx-src documentation

CngxCheckbox

cngx-checkbox

ComponentPrimaryOnPushNo encapsulationv0.1.0WCAG AA

projects/common/interactive/checkbox/checkbox.component.ts

Import#

import { CngxCheckbox } from '@cngx/common/interactive'

Description#

Single-value boolean checkbox with indeterminate support and W3C role="checkbox" semantics. Click, Space, and Enter all advance value; an indeterminate checkbox advances to value=true, indeterminate=false in a single step (per WAI-ARIA tristate semantics - there is no path that lands the checkbox back in 'mixed' from a user click).

value and indeterminate are both ModelSignal<boolean> so consumers can two-way-bind both: [(value)] for the canonical checked/unchecked state, [(indeterminate)] for the tri-state marker most often driven by a parent group's "some-but-not-all" computation. disabled is also a ModelSignal<boolean> to keep the CngxFormBridge's setDisabledState write path consistent across the family.

Visual indicator state is delegated to <cngx-checkbox-indicator> from @cngx/common/display; this interactive molecule owns role, keyboard, and ARIA wiring and composes the display atom. Per Pillar 3, the visual atom is reused - never re-drawn here.

aria-checked is a reactive computed: indeterminate() ? 'mixed' : value() ? 'true' : 'false'. The description span for disabledReason follows the same always-in-DOM rule as CngxToggle.

<cngx-checkbox [(value)]="acceptTerms">I accept the terms</cngx-checkbox>

<cngx-checkbox
  [(value)]="allSelected()"
  [(indeterminate)]="someSelected() && !allSelected()"
  (valueChange)="toggleAll($event)"
>Select all</cngx-checkbox>

https://cngxjs.github.io/cngx/examples/#/common/interactive/checkbox/group/basic-select-all-master-projected-leaves https://cngxjs.github.io/cngx/examples/#/common/interactive/checkbox/group/disabled-cascade https://cngxjs.github.io/cngx/examples/#/common/interactive/checkbox/base/basic-two-way-binding https://cngxjs.github.io/cngx/examples/#/common/interactive/checkbox/base/custom-check-dash-glyphs https://cngxjs.github.io/cngx/examples/#/common/interactive/checkbox/base/disabled https://cngxjs.github.io/cngx/examples/#/common/interactive/checkbox/base/tri-state-select-all-pattern https://cngxjs.github.io/cngx/examples/#/forms/field/form-primitives/coming-in-a-follow-up https://cngxjs.github.io/cngx/examples/#/forms/field/form-primitives/reactive-forms-same-atom-just-bind-formcontrol https://cngxjs.github.io/cngx/examples/#/forms/field/form-primitives/signal-forms-drop-the-atom-into-cngx-form-field

Metadata#

Host#

Providers#

CNGX_CONTROL_VALUE
useExisting CngxCheckbox
CNGX_FORM_FIELD_CONTROL
useExisting CngxCheckbox

Relationships

Index#

Inputs#

checkGlyph#TemplateRef | null
default null
dashGlyph#TemplateRef | null
default null
disabled#boolean
model()
default false
disabledReason#string
input()
default ''
errorMessageId#string | null
input()

Optional id of an external error message element (e.g. a sibling rendered by <cngx-form-field> or a consumer-owned <span>). The host emits aria-errormessage="<id>" only when aria-invalid="true" — symmetric with the sibling aria-invalid host binding (both gate on invalid() || errorState()). Consumers MUST render an element with the supplied id; passing an id without a matching element produces a dangling AT reference. Default null skips the attribute entirely.

default null
indeterminate#boolean
model()
default false
invalid#boolean
model()

Bridge-writable invalid state. model<boolean> mirrors disabled so external integrations (RF/Signal-Forms bridges, custom validity adapters) can drive it without a parallel API path - consumers typically read only.

default false
model()
default false

Outputs#

disabled#boolean
model()
indeterminate#boolean
model()
invalid#boolean
model()

Bridge-writable invalid state. model<boolean> mirrors disabled so external integrations (RF/Signal-Forms bridges, custom validity adapters) can drive it without a parallel API path - consumers typically read only.

model()

Instance Properties#

describedId#unknown
ProtectedReadonly
nextUid('cngx-checkbox-desc')
focused#unknown
Readonly
this.focusedState.asReadonly()
id#unknown
signal()Readonly
signal(nextUid('cngx-checkbox-')).asReadonly()

Methods#

handleClick#void
Protected
handleFocusIn#void
Protected
handleFocusOut#void
Protected
handleKeydown#void
Protected
handleKeydown(event: Event)
@parameventEvent

HostBindings#

BindingExpression
[attr.id]id()
[attr.aria-checked]ariaChecked()
[attr.aria-disabled]disabled() ? "true" : null
[attr.aria-invalid]ariaInvalid() ? "true" : null
[attr.aria-errormessage]ariaInvalid() ? errorMessageId() : null
[attr.aria-describedby]describedId
[attr.tabindex]hostTabindex()
[class.cngx-checkbox--checked]value()
[class.cngx-checkbox--indeterminate]indeterminate()
[class.cngx-checkbox--disabled]disabled()

HostListeners#

EventHandler
(click)click()
(keydown.space)keydown.space()
(keydown.enter)keydown.enter()
(focusin)focusin()
(focusout)focusout()

Default visuals for the interactive shell around <cngx-checkbox-indicator>. The host carries .cngx-checkbox and renders the indicator plus a .cngx-checkbox__label slot for the projected label text and a .cngx-checkbox__sr-only slot for assistive-only copy. The --cngx-checkbox-color and --cngx-checkbox-disabled-opacity tokens are owned by CngxCheckboxIndicator and read here without re-registration so the vocabulary stays unified.

State modifiers

  • --disabled - cursor: not-allowed + opacity dim via --cngx-checkbox-disabled-opacity

Slots

  • .cngx-checkbox__label - projected label content
  • .cngx-checkbox__sr-only - visually-hidden copy for AT

Inheritance

Layout and focus tokens cascade through the foundation:

  • --cngx-checkbox-gap -> --cngx-space-sm
  • --cngx-checkbox-focus-radius -> --cngx-radius-sm
  • --cngx-checkbox-sibling-gap - direct (defaults to 1rem)

Adjacent-sibling spacing (.cngx-checkbox + .cngx-checkbox) sits OUTSIDE the @scope block because @scope's subtree semantics block the + combinator from reaching a sibling scope-root. Override the sibling-gap token with 0 when the consumer wraps siblings in their own flex/grid container.

Index#

Layout

--cngx-checkbox-gap#*
Default value 0.5rem

Gap between the indicator and the label slot. Falls back to --cngx-space-sm.

--cngx-checkbox-sibling-gap#*
Default value 1rem

Horizontal spacing between adjacent inline <cngx-checkbox> siblings. Override with 0 if the consumer wraps siblings in its own flex/grid container.

State / Focus

--cngx-checkbox-focus-outline#*
Default value 2px solid currentColor

Focus-ring outline shorthand applied via outline on the host.

--cngx-checkbox-focus-offset#*
Default value 2px

Outline offset of the focus ring.

--cngx-checkbox-focus-radius#*
Default value 0.25rem

Corner radius applied while focused - keeps the ring rounded around the inline shell.