Select @ngb-bootstrap/core/select
<ngb-select>Component
NgbSelect
.form-control and
.combobox-toggle that opens an ngb-listbox in an overlay. It follows the WAI-ARIA select-only
combobox pattern. Enter, Space, Arrow Down or Up open the list; arrows, Home, End and typing move
through the options; Enter selects; Escape closes the list and keeps focus; Tab selects the
highlighted option and moves on. Focus stays on the field, and the highlighted option is
announced with aria-activedescendant .
It is a form control: ngModel , reactive forms and [(value)] all work. The value is the
selected option's value, or an array of values with multiple . Options come from ngb-option
and ngb-optgroup children, from the options input, or both. For a plain native picker use
<select ngbInput> instead.
<ngb-select label="Country" placeholder="Choose a country" clearable [(value)]="country">
<ngb-option value="fr">France</ngb-option>
<ngb-option value="de">Germany</ngb-option>
</ngb-select>
<ngb-select multiple [options]="users" [optionLabel]="userName" [formControl]="team" />| Name | Type | Default |
|---|---|---|
[(value)][(value)] . | Tnull | null |
[disabled]disabled input. Forms can also disable the control. | boolean | false |
[invalid] | boolean | undefined |
[placeholder] | string | '' |
[multiple] | boolean | false |
[display]chips (default) or count ("3 selected"). | NgbSelectDisplay | 'chips' |
[clearable] | boolean | false |
[clearLabel]clear string of NGB_I18N . | string | — |
[size]sm , md (default) or lg . | NgbSelectSize | 'md' |
[label] | string | — |
[labelledBy]<label> . | string | — |
[options]ngb-option children. | ReadonlyArray<T> | [] |
[optionValue]options . Defaults to the entry itself. | (option: T) => unknown | (option) => option |
[optionLabel]options . Defaults to String(entry) . | (option: T) => string | (option) => String(option) |
[optionDisabled]options is disabled. | (option: T) => boolean | () => false |
[compareWith]Object.is . | (a: unknown, b: unknown) => boolean | Object.is |
[emptyText]listbox.noResults string. | string | — |
[placement] | NgbPlacement | 'bottom-start' |
[(open)] | boolean | false |
(cleared) | void | — |
<ngb-listbox>Component
NgbListbox
role="option" rows in Bootstrap 6's .menu surface, so a listbox looks like a dropdown menu,
with a check mark on selected options and a highlight on the active one. Unlike a menu, it is for
choosing a value, not for running an action.
The active option is tracked with aria-activedescendant , so keyboard focus can stay in an
input or button that owns the list: pass its key events to onKeydown() . On its own the
listbox is focusable and handles the keys itself. Arrow keys, Home and End move (wrapping),
typing jumps to the next option that starts with the typed text, Enter or Space selects.
Describe the options with ngb-option and ngb-optgroup children, or give plain data with
[items] . value is the selected option's value, or an array of them with multiple .
<ngb-listbox label="Fruit" [(value)]="fruit">
<ngb-option value="apple">Apple</ngb-option>
<ngb-option value="pear" disabled>Pear</ngb-option>
</ngb-listbox>| Name | Type | Default |
|---|---|---|
[id]aria-controls points at it. | string | ngbId('ngb-listbox') |
[label] | string | — |
[labelledBy] | string | — |
[items]ngb-option and ngb-optgroup children are used. | ReadonlyArray<NgbListboxItem> | [] |
[(value)]multiple . Two-way bindable. | unknown | null |
[multiple]value is then an array. | boolean | false |
[compareWith]Object.is . | (a: unknown, b: unknown) => boolean | Object.is |
[activation] | NgbListboxActivation | 'selected' |
[focusable]onKeydown() . | boolean | true |
[emptyText]listbox.noResults string. | string | — |
[loading] | boolean | false |
(optionSelected) | unknown | — |
<ngb-optgroup>Component
NgbOptgroup
ngb-option s.
<ngb-optgroup label="Fruit">
<ngb-option value="apple">Apple</ngb-option>
</ngb-optgroup>| Name | Type | Default |
|---|---|---|
[label]required | string | — |
[disabled] | boolean | false |
<ngb-option>Component
NgbOption
ngb-listbox or ngb-select . It only describes the option, the list
itself draws it, so the label has to be text. Without a label input the element's text is
used.
<ngb-option value="fr">France</ngb-option>
<ngb-option [value]="user" [label]="user.name" disabled />| Name | Type | Default |
|---|---|---|
[value] | unknown | — |
[label] | string | — |
[disabled] | boolean | false |
NgbSelectDisplayType
type NgbSelectDisplay = 'chips' | 'count'NgbSelectSizeType
type NgbSelectSize = 'sm' | 'md' | 'lg'isNgbListboxGroupFunction
isNgbListboxGroup(item: NgbListboxItem): item is NgbListboxGroupNGB_LISTBOX_ENTRYConstant
InjectionToken<NgbListboxEntry>NgbListboxActivationType
type NgbListboxActivation = 'selected' | 'first' | 'none'NgbListboxEntryInterface
ngb-option and ngb-optgroup . A listbox or select finds them in its content
through this token, which keeps their order, and reads the plain data they stand for.
| Name | Type | Default |
|---|---|---|
itemrequired | () => NgbListboxItem | — |
NgbListboxGroupInterface
| Name | Type | Default |
|---|---|---|
labelrequired | string | — |
optionsrequired | ReadonlyArray<NgbListboxOption> | — |
disabled | boolean | — |
NgbListboxItemType
type NgbListboxItem = NgbListboxOption | NgbListboxGroupNgbListboxOptionInterface
| Name | Type | Default |
|---|---|---|
valuerequired | unknown | — |
labelrequired | string | — |
disabled | boolean | — |