In Angular Aria 22, a document editor's mention picker built from `ngCombobox` and an `ngListbox` popup lists every user whatever is typed and renders inline; why, and what fixes it?
answer
- coordination, not data
- filtering lives in user space
- combobox value is the typed text
- popup template renders where it sits
- connected overlay plus activedescendant
basics
~20 sAngular Aria's combobox only coordinates an input with its popup: ARIA states, expansion and keyboard forwarding. It neither filters nor positions. Filter options with a computed signal over the combobox's text value, and place the popup with the CDK's connected overlay.
solid answer
~40 s`ngCombobox` sets `role="combobox"`, `aria-expanded`, `aria-controls` and `aria-activedescendant` on the input, opens and closes the popup, and forwards arrow keys and Enter into the widget inside `ng-template ngComboboxPopup`. Its `value` model is just the text typed, a string. It never decides which options match, so the `@for` keeps rendering the whole user list; the fix is a `computed()` that filters people by that text. Nor does it position anything: the popup template renders where it sits in the page flow, which is why the angular.dev examples wrap it in a `cdkConnectedOverlay` anchored to the input. Inside the popup, mark the listbox `ngComboboxWidget`, set `focusMode="activedescendant"` and bind `[activeDescendant]`, so DOM focus stays in the input while arrows move the active person. In 22.0.0 this `Combobox` replaced the old combobox and autocomplete directives.
code
ts · 26 linesimport {Component, computed, signal} from '@angular/core';
import {Combobox, ComboboxPopup, ComboboxWidget} from '@angular/aria/combobox';
import {Listbox, Option} from '@angular/aria/listbox';
import {OverlayModule} from '@angular/cdk/overlay';
@Component({
selector: 'app-mention-picker',
imports: [Combobox, ComboboxPopup, ComboboxWidget, Listbox, Option, OverlayModule],
templateUrl: './mention-picker.html',
})
export class MentionPicker {
readonly people = [{id: 'u1', name: 'Ada'}, {id: 'u2', name: 'Grace'}];
readonly query = signal('');
readonly open = signal(false);
readonly picked = signal<string[]>([]);
readonly matches = computed(() =>
this.people.filter(p => p.name.toLowerCase().startsWith(this.query().toLowerCase())),
);
commit() {
const id = this.picked()[0];
// insert the mention for `id` into the document here
this.query.set('');
this.open.set(false);
}
}go deeper
Recall that ngCombobox goes on the input, ngComboboxPopup on an ng-template, and that the list you loop over must be filtered by your own code.
Explain the division of labour: the combobox owns ARIA states, expansion and key forwarding, its value is the text, and the listbox inside holds the selection array.
Diagnose unfiltered and inline popups from the directive's contract, then fix them with a computed signal, a connected overlay and activedescendant focus that keeps the caret in the input.
Argue for wrapping the combobox, filter and overlay once in the kit, and plan for the 22.0.0 combobox replacement when estimating upgrades of preview-era code.
## The scenario An in-house component kit for a document editor needs an **@-mention picker**: the author types a name and picks a person from a list. The team builds it on **Angular Aria 22** with `ngCombobox` on a search input and an `ngListbox` in the popup. Two bugs appear at once: the list never narrows, and the list renders inline, pushing the editor's text down instead of floating under the input. Both bugs have the same root cause. The Aria combobox is a **coordination primitive**. The angular.dev guide calls it the directive that coordinates a trigger element with a popup, and says filtering is managed in **user space**. ## What `ngCombobox` does and does not do | Concern | Who handles it | |---|---| | `role="combobox"`, `aria-expanded`, `aria-controls`, `aria-haspopup`, `aria-activedescendant` | `ngCombobox` | | Opening on typing or Down Arrow, closing on Escape or when focus leaves input and popup | `ngCombobox` (state in its `expanded` model) | | Forwarding arrow keys and Enter into the popup's widget | `ngCombobox` | | Holding the typed text | `ngCombobox`'s `value` model (a `string`) | | Deciding which options match the text | **you**, with a signal | | Placing the popup on screen | **you**, usually with the CDK overlay | | Writing the chosen person into the document | **you** | The popup is an `ng-template` marked `ngComboboxPopup` with `[combobox]` pointing at the combobox. It is conditionally rendered, but it is rendered **where the template sits**. Without an overlay around it, it takes part in normal layout: it pushes content, and an ancestor with `overflow: hidden` clips it. ## The fix, step by step 1. **Filter in a computed signal.** Bind `[(value)]="query"` on the input, then derive the list: `matches = computed(() => people.filter(p => p.name.toLowerCase().startsWith(query().toLowerCase())))`. Loop over `matches()`, not the full list. 2. **Position with a connected overlay.** Wrap the popup template in an `ng-template` carrying `cdkConnectedOverlay`, anchored to the input's container and opened by the combobox's `expanded` state. How that overlay picks a position and reacts to scrolling is overlay territory; here it simply lifts the list out of the flow. 3. **Register the widget.** Put `ngComboboxWidget` on the `ngListbox`. That is how the popup learns the element the input's `aria-controls` must name. 4. **Keep focus in the input.** Set `focusMode="activedescendant"`, `[tabindex]="-1"` and `[activeDescendant]="people.activeDescendant()"` on the listbox. DOM focus stays in the text field, so the caret and typing keep working, while `aria-activedescendant` tells assistive technology which person is active. 5. **Commit on purpose.** On click or Enter, read the listbox's `value` (an array), insert the mention, reset the query and set `expanded` to `false`. ```html <div #origin> <input ngCombobox #combobox="ngCombobox" aria-label="Mention a person" [(value)]="query" [(expanded)]="open" /> </div> <ng-template [cdkConnectedOverlay]="{origin, matchWidth: true}" [cdkConnectedOverlayOpen]="open()"> <ng-template ngComboboxPopup [combobox]="combobox"> <ul ngListbox ngComboboxWidget #people="ngListbox" focusMode="activedescendant" [tabindex]="-1" [activeDescendant]="people.activeDescendant()" [(value)]="picked" (click)="commit()" (keydown.enter)="commit()"> @for (p of matches(); track p.id) { <li ngOption [value]="p.id" [label]="p.name">{{ p.name }}</li> } </ul> </ng-template> </ng-template> ``` ## Inputs worth knowing - **`alwaysExpanded`** keeps the popup open; it does not filter anything. - **`inlineSuggestion`** shows a suggested completion inside the input; you compute it, and it filters nothing. - **`readonly`** turns the trigger into a select-style dropdown with no typing. - **`popupType`** on `ngComboboxPopup` (`'listbox'` by default, also `'tree'`, `'grid'` or `'dialog'`) sets what `aria-haspopup` announces. - **`softDisabled`** (default `true`) keeps a disabled combobox focusable. ## What changed in v22 The 22.0.0 release removed the **legacy combobox and autocomplete implementations** and promoted the former `SimpleCombobox` to `Combobox`, renaming every `simple-combobox` symbol and token (`SIMPLE_COMBOBOX_POPUP` became `COMBOBOX_POPUP`). The same release renamed the selection model `values` to `value` on the listbox and its siblings. Code written against a 21-era preview needs both changes before it compiles. ## Testing the picker Angular Aria ships a `ComboboxHarness` in `@angular/aria/combobox/testing`, loaded through the CDK's harness loader like any other harness. Its `open()`, `close()` and `isOpen()` let a test drive the picker without reaching into its DOM, so tests survive restyling. Pair it with a test that types a partial name and asserts the listbox shows only matching people, because filtering is the part the directive does not own. ## Why it is built this way Keeping data and layout out of the combobox lets one primitive back an autocomplete, a select, a multiselect, a tree picker and a date grid. The price is that every consumer writes the same filtering and overlay code, which is exactly what an in-house kit should wrap once.
- Why does the angular.dev autocomplete example still announce 'No results found' through a live region?Because an empty filtered list is your state, not the combobox's: the directive cannot know that zero options matched. The example renders a visually hidden `aria-live="polite"` element whose text changes when the filtered list is empty, so screen-reader users hear the outcome of their typing. A mention picker should do the same.
- How would you turn the same pieces into a select-style person picker with no typing?Put `ngCombobox` on a non-editable trigger, such as a `div` or button, or add `readonly` to the input. The popup opens on click or the arrow keys, typeahead in the listbox replaces filtering, and the listbox's `value` array becomes the selection you display in the trigger. The angular.dev select pattern is built this way.
- ngCombobox filters the popup's options against what the user types
- Angular Aria positions the combobox popup under the input on its own
- The combobox value model holds the selected option values
- An ngListbox inside the popup template works without ngComboboxWidget
- In Angular Aria 22 you import SimpleCombobox for an editable input
Assumes Angular Aria 22; 22.0.0 removed the legacy combobox and autocomplete and promoted SimpleCombobox to Combobox.