Skip to content
Okaapiأوكابي
Framework for the code
Theme
Okaapi on GitHub

Chapter 05 Choices

Select

One choice from a list. Arrow keys, Home and End, and typing the first letters all move through the options; Escape and Tab close the list and return focus.

Use it in Angular
import { SelectComponent, type SelectOption } from '@okaapi-ui/angular';
// Works with formControlName, [formControl] and ngModel.
Works with

Basic

City
Angular
cities: SelectOption<string>[] = [
  { value: 'cai', label: 'Cairo' },
  { value: 'alx', label: 'Alexandria' },
];

<ui-select label="City" placeholder="Choose a city" [options]="cities" formControlName="city" />

With an error

Size
Angular
sizes: SelectOption<string>[] = [
  { value: 's', label: 'Small' },
  { value: 'm', label: 'Medium' },
  { value: 'l', label: 'Large', disabled: true },
];

<ui-select label="Size" [options]="sizes" formControlName="size" error="Choose a size" />

In Arabic

المدينة
Angular
<!-- dir="rtl" on the page or any ancestor -->
<ui-select label="المدينة" placeholder="اختار المدينة" [options]="cities" formControlName="city" />

When to use something else

If you needUse
A long list the reader searchesCombobox
Two to five options that fit on screenRadio group
Actions, not valuesMenu

Inputs

NameTypeDefaultWhat it does
labelstring — Required. The visible label; it names the button and the list.
optionsSelectOption<T>[] — Required. { value, label, disabled? } for each option.
placeholderstring''Shown while nothing is chosen.
errorstring — The translated error. Marks the select invalid and announces the message.
compareWith(a: T, b: T) => boolean===How to match the form value to an option, for object values.
testIdstring — data-testid on the button; options get -option-<index>.

Keyboard and screen readers

KeysWhat they do
Enter or Space or Up or Down Open the list.
Up or Down or Home or End Move through the options.
Letters Jump to the option that starts with them.
Enter or Space Pick the option.
Escape or Tab Close the list, and put focus back on the button.
  • Read as a list box, with the chosen option and the field’s label.