Chapter 05 Choices
Segmented control
One choice from two to five short options, side by side: a view, a period, a size. Radio buttons underneath, so Tab reaches the group and the arrow keys move the choice. The chosen one is lifted onto a tile with an edge, not just coloured.
import { SegmentedControlComponent } from '@okaapi-ui/angular';
// Works with formControlName, [formControl] and ngModel.A period
<ui-segmented-control label="Period" [options]="periods" formControlName="period" />
periods = [
{ value: 'day', label: 'Day' },
{ value: 'week', label: 'Week' },
{ value: 'month', label: 'Month' },
];Icons only
The words stay for screen readers. Keep icons that everyone reads the same way.
<ui-segmented-control label="View" iconOnly [options]="views" formControlName="view" />
views = [
{ value: 'list', label: 'List', icon: 'list' },
{ value: 'grid', label: 'Grid', icon: 'layout-grid' },
];Full width
block shares the width equally, as in a narrow panel or on a phone.
<ui-segmented-control label="Delivery" block [options]="delivery" formControlName="speed" />In Arabic
<ui-segmented-control label="الفترة" [options]="periods" formControlName="period" />When to use something else
| If you need | Use |
|---|---|
| Show different panels of content | Tabs |
| A choice sent with a form | Radio group |
| One option that is on or off | Toggle |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
label | string | — | Names the group for screen readers. |
options | { value, label, icon?, disabled? }[] | — | Two to five short options. |
iconOnly | boolean | false | Shows only the icons; the words are still read. |
block | boolean | false | Fills the width, segments sharing it. |
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. |
- Radio buttons underneath; the chosen option is lifted onto a tile with an edge, not only coloured.