-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy pathautocomplete-disabled-example.ts
More file actions
53 lines (47 loc) · 1.62 KB
/
autocomplete-disabled-example.ts
File metadata and controls
53 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Combobox, ComboboxPopup, ComboboxWidget} from '@angular/aria/simple-combobox';
import {Listbox, Option} from '@angular/aria/listbox';
import {
afterRenderEffect,
ChangeDetectionStrategy,
Component,
computed,
signal,
viewChild,
} from '@angular/core';
import {COUNTRIES} from '../countries';
import {OverlayModule} from '@angular/cdk/overlay';
import {FormsModule} from '@angular/forms';
/** @title Disabled autocomplete. */
@Component({
selector: 'autocomplete-disabled-example',
templateUrl: 'autocomplete-disabled-example.html',
styleUrl: '../autocomplete.css',
imports: [Combobox, ComboboxPopup, ComboboxWidget, Listbox, Option, OverlayModule, FormsModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AutocompleteDisabledExample {
/** The selected value of the combobox. */
readonly listbox = viewChild(Listbox);
readonly combobox = viewChild(Combobox);
popupExpanded = signal(false);
searchString = signal('United States of America');
selectedOption = signal<string[]>([]);
/** The query string used to filter the list of countries. */
query = computed(() => this.searchString());
/** The list of countries filtered by the query. */
countries = computed(() =>
COUNTRIES.filter(country => country.toLowerCase().startsWith(this.query().toLowerCase())),
);
constructor() {
afterRenderEffect(() => {
this.listbox()?.scrollActiveItemIntoView();
});
}
}