Chapter 05 Choices
Radio group
One choice from a short list, with every option in view. Native radios: Tab reaches the group, arrow keys move the choice. For more than five or six options, use a select.
import { RadioGroupComponent } from '@okaapi-ui/angular';
// Options are { value, label, disabled? }, as for ui-select.Works with
One per line
Same day is not available for this address.
<ui-radio-group
label="Delivery"
hint="Same day is not available for this address."
[options]="speeds"
formControlName="speed"
/>Side by side, with an error
Short answers can sit on one line. An error adds a red edge and the message, which is announced.
Choose yes or no
<ui-radio-group
label="Do you have a parking space?"
orientation="horizontal"
[options]="yesNo"
formControlName="parking"
[error]="form.controls.parking.invalid ? 'Choose yes or no' : undefined"
/>In Arabic
<ui-radio-group label="التوصيل" [options]="speeds" formControlName="speed" />When to use something else
| If you need | Use |
|---|---|
| Several choices at once | Checkbox |
| More than about 7 options | Select |
| Switch the view of the page | Segmented control |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Required. Names the group. |
options | RadioOption<T>[] | — | Required. { value, label, disabled? } for each radio. |
orientation | 'vertical' | 'horizontal' | 'vertical' | Side by side for two or three short answers. |
hint | string | — | Help text under the label, read with the group. |
error | string | — | The translated error. Marks the group invalid and announces the message. |
compareWith | (a: T, b: T) => boolean | === | How to match the form value to an option, for object values. |
testId | string | — | data-testid prefix; each radio gets -<index>. |
Keyboard and screen readers
| Keys | What they do |
|---|---|
| Tab | Reach the group, on the chosen option. |
| Arrow keys | Move the choice to the next or previous option. |
- Native radios in a named group, so the group name is read first.