Create

Form

Checkbox

Copy page View as Markdown Open in ChatGPT Open in Claude

A control that allows the user to toggle between checked and not checked.

Usage#

app.component.ts
import { WdsCheckboxComponent } from '@wds/angular/checkbox';

Examples#

Default#

The content of the element is the label.

Accept terms and conditions

Description#

The description slot adds helper text below the label.

Accept terms and conditions By clicking this checkbox, you agree to the terms and conditions.

Disabled#

Enable notifications Remember me

Indeterminate#

indeterminate shows a dash, e.g. for "select all" when only some items are selected. A click clears it.

Select all

Group#

wds-field-set with a legend groups related checkboxes; data-checkbox-group on wds-field-group tightens the spacing. wds-change bubbles, so one listener on the group handles all checkboxes.

Show these items on the desktop:Select the items you want to show on the desktop.Hard disksExternal disksCDs, DVDs, and iPodsConnected servers

{ "hardDisks": true, "externalDisks": true, "media": false, "servers": false }

Select all#

A parent checkbox for a group: checked when every item is checked, indeterminate when only some are. A click on it checks or unchecks the whole group. indeterminate is state for the app to set; the checkbox only clears it on a click.

ToppingsSelect allCheeseMushroomsOlives

Choice card#

variant="card" turns the checkbox into a card: a click anywhere on it toggles the checkbox.

Analytics Usage reports and statistics. Backups Daily copies of your data. Priority support A reply within 24 hours.

Invalid#

invalid shows the error state and sets aria-invalid.

Accept terms and conditions

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsCheckboxField connects the checkbox to [formField]. For a boolean, required() means checked: false counts as empty.

Accept terms and conditions Send me product updates At most one email a month.Submit

Submitted: —

Template-driven#

WdsCheckboxValueAccessor makes ngModel work on wds-checkbox. Add WdsCheckboxRequiredValidator so that required means checked, as on a native checkbox; without it false is a valid value.

Accept terms and conditions Send me product updates At most one email a month.Submit

Submitted: —

Reactive forms#

The same WdsCheckboxValueAccessor works with formControl and formControlName. Use Validators.requiredTrue for a checkbox that must be checked.

Accept terms and conditions Send me product updates At most one email a month.Submit

Submitted: —

API References#

wds-checkbox#

A checkbox. A native <input type="checkbox"> inside (keyboard, accessibility, click on the label).

Attributes

AttributeTypeDefaultDescription
indeterminatebooleanfalseIndeterminate state (e.g. "select all" when some items are selected): a dash instead of a check, aria-checked="mixed". A click clears it, as in a native checkbox.
checkedbooleanfalseChecked state. Setting it from code does not fire wds-change.
disabledbooleanfalseDisables the field and excludes it from form submission.
invalidbooleanfalseError state: red border and aria-invalid.
requiredbooleanfalseThe field must be checked for the form to be valid (e.g. accepting terms).
namestring''Field name in the form. Reflected to the attribute, which FormData uses (also when a framework sets it as a property).
valuestring'on'Value submitted with the form when the field is checked.
variantWdsToggleVariant'default'card is a clickable card with a border and the control on the right.

Events

EventDescription
wds-changeCustomEvent<WdsToggleChangeDetail>The user changed the checked state.

Methods

MethodDescription
formResetCallback()
formDisabledCallback(disabled: boolean)
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

Slots

SlotDescription
(default)Label.
descriptionHelper text below the label (linked with aria-describedby).

CSS parts (::part)

PartDescription
rootThe container (the card in the card variant).
controlThe native <input>.
iconThe check icon.
labelThe label.
descriptionThe helper text.

CSS custom properties

PropertyDescription
--wds-checkbox-borderBorder color.
--wds-checkbox-checkedChecked color.

Accessibility#

Screen reader#

wds-checkbox renders a native <input type="checkbox">, so screen readers announce it as a checkbox with its state. indeterminate is announced as mixed (aria-checked="mixed").

The content of the element is a native <label> of the input and the description slot is linked with aria-describedby. Without visible text give the checkbox an aria-label: it is forwarded to the input.

invalid sets aria-invalid="true" and required sets aria-required="true"; disabled disables the native input. In wds-field-set the legend names the group.

The checkbox takes part in forms: when checked, its value (default on) is submitted under name.

Keyboard support#

KeyFunction
TabMoves focus to the checkbox. A disabled checkbox is skipped.
SpaceChecks or unchecks the checkbox.
Footer