Chapter 05 Choices
Checkbox
A yes or no that is saved with the form, such as accepting the terms. The native checkbox in the primary colour; the whole label is the hit area, at least 44px tall.
import { CheckboxComponent } from '@okaapi-ui/angular';
// The value is true or false. Works with formControlName, [formControl] and ngModel.Works with
With a hint
One email per order, no adverts.
<ui-checkbox
label="Email me about my orders"
hint="One email per order, no adverts."
formControlName="updates"
/>With an error
The message is announced and tied to the checkbox, so a screen reader hears why the form did not send.
Accept the terms to continue
<ui-checkbox
label="I accept the terms"
formControlName="terms"
[error]="form.controls.terms.invalid ? 'Accept the terms to continue' : undefined"
/>Some of a list
indeterminate shows a dash on a parent checkbox when only some items under it are ticked.
<ui-checkbox label="All files" [indeterminate]="some()" formControlName="all" />In Arabic
<!-- dir="rtl" on the page or any ancestor -->
<ui-checkbox label="ابعتلي إيميل عن طلباتي" />When to use something else
| If you need | Use |
|---|---|
| One choice from a few options | Radio group |
| A setting that takes effect at once | Switch |
| Several choices from a long list | Combobox or Chip input |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. The visible label; the whole label is the hit area. |
hint | string | — | Help text under the checkbox, read with it. |
error | string | — | The translated error. Marks the checkbox invalid and announces the message. |
indeterminate | boolean | false | Shows a dash: some of the items under it are ticked. |
testId | string | — | data-testid on the input, for tests. |
Keyboard and screen readers
| Keys | What they do |
|---|---|
| Space | Tick or untick it. |
- The native checkbox, named by its label; the whole label is the hit area.