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

Chapter 05 Choices

Combobox

A text field that filters a list as you type, for a long list such as countries. Focus stays in the field: arrow keys move through the matches, Enter picks one and Escape closes the list. The value is always one of the options.

Use it in Angular
import { ComboboxComponent } from '@okaapi-ui/angular';
// Options are { value, label, disabled? }, as for ui-select. Add @angular/cdk/overlay-prebuilt.css.
Works with

Countries

Where the company is registered.

Angular
<ui-combobox
  label="Country"
  placeholder="Start typing"
  hint="Where the company is registered."
  [options]="countries"
  formControlName="country"
/>

With an error

Angular
<ui-combobox
  label="Country of birth"
  [options]="countries"
  formControlName="birth"
  [error]="form.controls.birth.invalid ? 'Choose a country' : undefined"
/>

In Arabic

Angular
<ui-combobox label="الدولة" emptyText="مفيش نتايج" [options]="countries" />

When to use something else

If you needUse
One choice from fewer than about 10 optionsSelect
Several valuesChip input
Find a page or run a command from anywhereCommand palette

Inputs

NameTypeDefaultWhat it does
labelstring — Required. Names the field and the list.
optionsSelectOption<T>[] — Required. { value, label, disabled? }. The label is what is matched.
placeholderstring — Shown while the field is empty.
hint, errorstring — As for the text field.
emptyTextstring'No matches' from labelsAnnounced when nothing matches; pass the translated text.
compareWith(a: T, b: T) => boolean===How to match the form value to an option, for object values.
testIdstring — data-testid on the input; options get -option-<index>.

Keyboard and screen readers

KeysWhat they do
Up or Down Open the list and move through the matches, wrapping round.
Enter Pick the highlighted match.
Escape Close the list.
  • Focus stays in the field; the highlighted match is read as it moves.