Checkbox

A labelled checkbox for a yes/no choice that takes effect when the form is submitted, such as accepting terms or opting in. For settings that apply at once, use a toggle switch.

  • vig-checkbox
Import
import { Checkbox } from '@vigdx/ui/checkbox';

Basic

Bind [(value)] to a boolean signal. The whole label is clickable; hint adds help text below it.

One email every Monday, unsubscribe at any time.

Remember: true · Digest: false

States

disabled greys out box and label. readonly keeps the box focusable but ignores clicks and Space. required adds an asterisk to the label.

Error

Errors show once the checkbox is touched and invalid ; the box turns red and the message appears below. errorMessages replaces the built-in text for each error kind.

Accept the terms to continue.

Hidden label

In a table or matrix where the headers already name each column, hideLabel hides the label text but keeps it as the accessible name. Make each label unique, for example by including the row name.

Notification channels
EventEmailPush
New comment

Mention

Weekly report

Reactive Forms

Import VigValueAccessor next to the component to use formControlName , [formControl] or ngModel . Use Validators.requiredTrue for a box that must be checked.

{
  "updates": false,
  "privacy": false
}

Signal Forms

vig-checkbox implements FormValueControl<boolean> . Signal Forms' required() treats false as empty, so it makes the box mandatory.

Valid: no

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="checkbox"][data-part="root"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="checkbox"]

Checkbox styling hooks
Part Element data-state
root The <label> wrapping box and text. checked, unchecked, indeterminate
control Wrapper of the box and its check mark. —
input The native checkbox (the visible box). —
indicator The check mark or indeterminate dash. —
label The label text. —
hint The vig-hint (a display: contents host; style its text part). —
disabled-reason The vig-hint with the disabled reason ( display: contents ). —
error The vig-field-error (a display: contents host; style its message part). —

Accessibility

  • A native <input type="checkbox"> inside its <label>: Space toggles it and the label text is its accessible name.
  • label is required. With hideLabel the text is visually hidden but still read out, so keep it descriptive.
  • Hint, disabled reason and error are linked through aria-describedby; a touched, invalid box sets aria-invalid="true".
  • Native checkboxes have no read-only state, so readonly reverts each change and sets aria-readonly="true"; tell users why the box cannot be changed, for example in the hint.
  • indeterminate sets the native mixed state, announced as "mixed" or "partially checked"; the next click clears it.
  • The box scales with the font size (1.25em) and shows a focus ring on keyboard focus.

API

Checkbox

vig-checkbox component
Checkbox props
Name Type Default Description
dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
errorMessagesRecord<string, string>—
—
errorsreadonly ValidationError.WithOptionalFieldTree[][]
—
hiddenbooleanfalse
—
hideLabelbooleanfalse

Keeps the label for assistive tech only, e.g. inside a table cell or a matrix.

hintstring | undefinedundefined
—
indeterminate model booleanfalse

Mixed state, e.g. a "select all" whose items are partly selected. Sets the native indeterminate property (exposed as aria-checked="mixed") and draws a dash; the browser clears it on the next click, which this model mirrors.

invalidbooleanfalse
—
label required string—
—
namestring''
—
pendingbooleanfalse
—
readonlybooleanfalse
—
requiredbooleanfalse
—
touchedbooleanfalse
—
value model booleanfalse
—

VigValueAccessor

directive

Bridges the vigdx form fields to Reactive Forms (formControl, formControlName) and template-driven forms (ngModel). Import it next to the component; Signal Forms ([formField]) need no accessor.

VigValueAccessor methods
Signature Description
registerOnChange(fn: (value: unknown) => void): void
—
registerOnTouched(fn: () => void): void
—
setDisabledState(disabled: boolean): void
—
writeValue(value: unknown): void
—

Are you sure?