For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /dolan/checkbox.md.

Checkbox

A box that toggles a check mark on tap, with its label beside it.

Installation

npx @blotch/dolan add checkbox
import { UiCheckbox } from '../components/ui/checkbox';

Usage

src/app/app.ts
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
import { UiCheckbox } from '../components/ui/checkbox';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, UiCheckbox],
  template: ` <ui-checkbox [(checked)]="accepted" label="Accept the terms" /> `,
})
export class App {
  protected readonly accepted = signal(false);
}
  • The whole row toggles it, label included. On a phone the words are the easier target.
  • The row is 44px tall at least, and a long label wraps beside the box.
  • The check mark pops in and out when the state changes.

Without a label

<view class="flex flex-row items-center gap-3">
  <ui-checkbox [(checked)]="done" accessibility-label="Done" />
  <text class="text-base text-foreground">Buy milk</text>
</view>
  • Without a label, the checkbox is only the box: 22px, lined up with what's around it.
  • Its tap area still reaches 48px across, a comfortable size for a finger, without taking that room in the layout.
  • Give it an accessibility-label, so a screen reader can name it.

Disabled

<ui-checkbox disabled />

<ui-checkbox disabled [checked]="true" />

A disabled checkbox dims and ignores taps.

Listen without a signal

<ui-checkbox (changed)="onNewsletter($event)" />

changed emits the new state after each tap.

Forms

checked is a model(), so it works with every Angular forms API:

<ui-checkbox [formField]="profile.field" />
<ui-checkbox [formControl]="control" />
<ui-checkbox [(ngModel)]="value" />

A tap marks the field touched, so its error can show. UiCheckbox implements Signal Forms' FormCheckboxControl. See Forms.

API

UiCheckbox

InputTypeDefaultDescription
checkedbooleanfalseWhether it's checked. Supports [(checked)].
labelstring''Text beside the box. The whole row then toggles the checkbox.
accessibility-labelstring''What a screen reader calls a checkbox without a label.
disabledbooleanfalseDims the checkbox and ignores taps.
classstring''Extra Tailwind classes for the checkbox: the row, or the box alone.
OutputTypeDescription
changedbooleanEmits the new state after a tap.
checkedChangebooleanEmits the new state, for [(checked)].
touchvoidEmits after a tap, for forms: the field counts as touched.

UiCheckbox also has a public toggle() method, which does nothing while disabled.

Accessibility

  • A screen reader reads the checkbox as one button, named by its label (or accessibility-label), with the value "Checked" or "Unchecked", in the words of provideAccessibilityWords() when the app gives its own.
  • A disabled checkbox is read as dimmed.
  • Switch: an on/off control for settings
  • Radio Group: pick one of several options
  • Label: a label of your own, beside a checkbox without one