Skip to content

Commit 3c6f299

Browse files
authored
docs(aria/combobox): update the simple-combobox examples to open on click (#33184)
* docs(aria/combobox): update the simple-combobox examples to open on click * docs(aria/combobox): update highlight examples to not have inlineSuggestion on open but also will update as you navigate
1 parent 60234c2 commit 3c6f299

16 files changed

Lines changed: 67 additions & 49 deletions

File tree

src/aria/simple-combobox/simple-combobox.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ describe('Combobox', () => {
12111211
[alwaysExpanded]="alwaysExpanded()"
12121212
[tabindex]="tabIndex()"
12131213
(focusout)="onBlur()"
1214+
(click)="popupExpanded.set(true)"
12141215
/>
12151216
12161217
<ng-template ngComboboxPopup [combobox]="combobox">
@@ -1556,6 +1557,7 @@ class ComboboxGridExample {
15561557
(input)="onInput()"
15571558
[disabled]="readonly()"
15581559
(focusout)="onBlur()"
1560+
(click)="combobox.expanded.set(true)"
15591561
/>
15601562
15611563
<ng-template ngComboboxPopup [combobox]="combobox">
@@ -1619,6 +1621,7 @@ class ComboboxListboxAutoSelectExample {
16191621
[(expanded)]="popupExpanded"
16201622
[inlineSuggestion]="value()[0] || options()[0]"
16211623
[disabled]="readonly()"
1624+
(click)="popupExpanded.set(true)"
16221625
/>
16231626
16241627
<ng-template ngComboboxPopup [combobox]="combobox">

src/components-examples/aria/simple-combobox/simple-combobox-auto-select/simple-combobox-auto-select-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div #origin class="example-combobox-input-container">
33
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
44
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search states..."
5-
[(value)]="searchString" [(expanded)]="popupExpanded" />
5+
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
66
</div>
77

88
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"

src/components-examples/aria/simple-combobox/simple-combobox-autocomplete-auto-select/simple-combobox-autocomplete-auto-select-example.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
placeholder="Select a country"
99
[(value)]="searchString"
1010
[(expanded)]="popupExpanded"
11+
(click)="popupExpanded.set(true)"
1112
/>
1213
<button
1314
class="example-clear-button"
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
<div class="example-combobox-container">
22
<div #origin class="example-autocomplete">
33
<span class="example-search-icon material-symbols-outlined" translate="no">search</span>
4-
<input
5-
ngCombobox
6-
#combobox="ngCombobox"
7-
aria-label="Label dropdown"
8-
placeholder="Select a country"
9-
[(value)]="searchString"
10-
[(expanded)]="popupExpanded"
11-
[inlineSuggestion]="selectedOption()[0] || countries()[0]"
12-
/>
13-
<button
14-
class="example-clear-button"
15-
aria-label="Clear"
16-
(keydown)="onKeydown($event)"
17-
(click)="clear()"
18-
>
4+
<input ngCombobox #combobox="ngCombobox" aria-label="Label dropdown" placeholder="Select a country"
5+
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)"
6+
(keydown.arrowdown)="navigated.set(true)" (keydown.arrowup)="navigated.set(true)"
7+
[inlineSuggestion]="(searchString() || navigated()) ? selectedOption()[0] : undefined" />
8+
<button class="example-clear-button" aria-label="Clear" (keydown)="onKeydown($event)" (click)="clear()">
199
<span aria-hidden="true" class="example-clear-icon material-symbols-outlined">close</span>
2010
</button>
2111
</div>
@@ -24,23 +14,24 @@
2414
{{countries().length === 0 ? 'No results found for ' + query() : ''}}
2515
</div>
2616

27-
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true">
17+
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}"
18+
[cdkConnectedOverlayOpen]="true">
2819
<ng-template ngComboboxPopup [combobox]="combobox">
2920
<div class="example-popup">
3021
@if (countries().length === 0) {
31-
<div class="example-no-results">No results found</div>
22+
<div class="example-no-results">No results found</div>
3223
}
3324

34-
<div ngListbox ngComboboxWidget focusMode="activedescendant" [tabindex]="-1" [(value)]="selectedOption"
25+
<div ngListbox ngComboboxWidget focusMode="activedescendant" [tabindex]="-1" selectionMode="follow" [(value)]="selectedOption"
3526
(click)="onCommit()" (keydown.enter)="onCommit()">
3627
@for (country of countries(); track country) {
37-
<div ngOption [value]="country" [label]="country" [disabled]="country === 'Brazil'">
38-
<span class="example-option-label">{{country}}</span>
39-
<span class="example-check-icon material-symbols-outlined" translate="no">check</span>
40-
</div>
28+
<div ngOption [value]="country" [label]="country" [disabled]="country === 'Brazil'">
29+
<span class="example-option-label">{{country}}</span>
30+
<span class="example-check-icon material-symbols-outlined" translate="no">check</span>
31+
</div>
4132
}
4233
</div>
4334
</div>
4435
</ng-template>
4536
</ng-template>
46-
</div>
37+
</div>

src/components-examples/aria/simple-combobox/simple-combobox-autocomplete-highlight/simple-combobox-autocomplete-highlight-example.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ChangeDetectionStrategy,
1414
Component,
1515
computed,
16+
effect,
1617
signal,
1718
viewChild,
1819
} from '@angular/core';
@@ -36,6 +37,7 @@ export class SimpleComboboxAutocompleteHighlightExample {
3637
popupExpanded = signal(false);
3738
searchString = signal('');
3839
selectedOption = signal<string[]>([]);
40+
navigated = signal(false);
3941

4042
/** The query string used to filter the list of countries. */
4143
query = computed(() => this.searchString());
@@ -49,6 +51,12 @@ export class SimpleComboboxAutocompleteHighlightExample {
4951
afterRenderEffect(() => {
5052
this.listbox()?.scrollActiveItemIntoView();
5153
});
54+
55+
effect(() => {
56+
if (!this.popupExpanded()) {
57+
this.navigated.set(false);
58+
}
59+
});
5260
}
5361

5462
/** Clears the query and the listbox value. */

src/components-examples/aria/simple-combobox/simple-combobox-autocomplete-manual/simple-combobox-autocomplete-manual-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div #origin class="example-autocomplete">
33
<span class="example-search-icon material-symbols-outlined" translate="no">search</span>
44
<input ngCombobox #combobox="ngCombobox" aria-label="Label dropdown" placeholder="Select a country"
5-
[(value)]="searchString" [(expanded)]="popupExpanded" />
5+
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
66
<button class="example-clear-button" aria-label="Clear" (keydown)="onKeydown($event)" (click)="clear()">
77
<span aria-hidden="true" class="example-clear-icon material-symbols-outlined">close</span>
88
</button>

src/components-examples/aria/simple-combobox/simple-combobox-datepicker/simple-combobox-datepicker-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<span class="material-symbols-outlined example-icon example-search-icon">calendar_month</span>
44
<input #comboboxInput ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Pick a date..."
55
[(value)]="selection" [(expanded)]="popupExpanded" aria-describedby="date-format-hint"
6-
(keydown)="onInputKeydown($event)" />
6+
(keydown)="onInputKeydown($event)" (click)="popupExpanded.set(true)" />
77
</div>
88

99
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: false}"

src/components-examples/aria/simple-combobox/simple-combobox-grid/simple-combobox-grid-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div #origin class="example-combobox-input-container">
33
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
44
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search..."
5-
[(value)]="searchString" [(expanded)]="popupExpanded" (blur)="onBlur()" />
5+
[(value)]="searchString" [(expanded)]="popupExpanded" (blur)="onBlur()" (click)="popupExpanded.set(true)" />
66
</div>
77

88
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"

src/components-examples/aria/simple-combobox/simple-combobox-highlight/simple-combobox-highlight-example.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
<div #origin class="example-combobox-input-container">
33
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
44
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search states..."
5-
[(value)]="searchString" [(expanded)]="popupExpanded"
6-
[inlineSuggestion]="selectedOption()[0] || options()[0]?.name" />
5+
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)"
6+
(keydown.arrowdown)="navigated.set(true)" (keydown.arrowup)="navigated.set(true)"
7+
[inlineSuggestion]="(searchString() || navigated()) ? selectedOption()[0] : undefined" />
78
</div>
89

910
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"
1011
[cdkConnectedOverlayDisableClose]="true">
1112
<ng-template ngComboboxPopup [combobox]="combobox">
12-
<div #listbox="ngListbox" ngListbox ngComboboxWidget class="example-listbox example-popup" focusMode="activedescendant"
13-
[tabindex]="-1" [(value)]="selectedOption" (click)="onCommit()" (keydown.enter)="onCommit()"
14-
[activeDescendant]="listbox.activeDescendant()">
13+
<div #listbox="ngListbox" ngListbox ngComboboxWidget class="example-listbox example-popup"
14+
focusMode="activedescendant" [tabindex]="-1" [(value)]="selectedOption" (click)="onCommit()"
15+
(keydown.enter)="onCommit()" [activeDescendant]="listbox.activeDescendant()">
1516
@for (option of options(); track option.name) {
16-
<div class="example-option example-selectable example-stateful" ngOption [value]="option.name" [label]="option.name"
17-
[disabled]="option.disabled">
17+
<div class="example-option example-selectable example-stateful" ngOption [value]="option.name"
18+
[label]="option.name" [disabled]="option.disabled">
1819
<span>{{option.name}}</span>
1920
<span aria-hidden="true" class="material-symbols-outlined example-icon example-selected-icon">check</span>
2021
</div>

src/components-examples/aria/simple-combobox/simple-combobox-highlight/simple-combobox-highlight-example.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {Combobox, ComboboxPopup, ComboboxWidget} from '@angular/aria/simple-combobox';
1010
import {Listbox, Option} from '@angular/aria/listbox';
11-
import {afterRenderEffect, Component, computed, signal, viewChild} from '@angular/core';
11+
import {afterRenderEffect, Component, computed, effect, signal, viewChild} from '@angular/core';
1212
import {OverlayModule} from '@angular/cdk/overlay';
1313

1414
/** @title Simple Combobox Highlight */
@@ -24,6 +24,7 @@ export class SimpleComboboxHighlightExample {
2424
popupExpanded = signal(false);
2525
searchString = signal('');
2626
selectedOption = signal<string[]>([]);
27+
navigated = signal(false);
2728

2829
options = computed(() =>
2930
states.filter(state => state.name.toLowerCase().startsWith(this.searchString().toLowerCase())),
@@ -33,6 +34,12 @@ export class SimpleComboboxHighlightExample {
3334
afterRenderEffect(() => {
3435
this.listbox()?.scrollActiveItemIntoView();
3536
});
37+
38+
effect(() => {
39+
if (!this.popupExpanded()) {
40+
this.navigated.set(false);
41+
}
42+
});
3643
}
3744

3845
onCommit() {

0 commit comments

Comments
 (0)