Skip to content

Commit 017caa3

Browse files
committed
fix(aria/combobox): fix autocomplete examples and add comments explaining combobox selection behavior (#32714)
(cherry picked from commit c57e6a1)
1 parent c56a948 commit 017caa3

File tree

8 files changed

+18
-13
lines changed

8 files changed

+18
-13
lines changed

src/aria/private/combobox/combobox.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,11 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
641641
select(opts: {item?: T; commit?: boolean; close?: boolean} = {}) {
642642
const controls = this.listControls();
643643

644+
// When no item is specified (e.g. on keyboard toggle), get the active item instead.
645+
// Note: this is only necessary for disabled check, as select/toggle will check active item too.
644646
const item = opts.item ?? controls?.getActiveItem();
645647

648+
// Check if item is disabled before proceeding.
646649
if (item?.disabled()) {
647650
return;
648651
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<input
55
aria-label="Label dropdown"
66
placeholder="Select a country"
7-
[(ngModel)]="query"
87
ngComboboxInput
98
/>
109
<button

src/components-examples/aria/autocomplete/autocomplete-auto-select/autocomplete-auto-select-example.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
ChangeDetectionStrategy,
1919
Component,
2020
computed,
21-
signal,
2221
viewChild,
2322
viewChildren,
2423
} from '@angular/core';
@@ -55,8 +54,11 @@ export class AutocompleteAutoSelectExample {
5554
/** A reference to the ng aria combobox. */
5655
combobox = viewChild<Combobox<string>>(Combobox);
5756

57+
/** A reference to the ng aria combobox input. */
58+
comboboxInput = viewChild<ComboboxInput>(ComboboxInput);
59+
5860
/** The query string used to filter the list of countries. */
59-
query = signal('');
61+
query = computed(() => this.comboboxInput()?.value() || '');
6062

6163
/** The list of countries filtered by the query. */
6264
countries = computed(() =>
@@ -75,7 +77,7 @@ export class AutocompleteAutoSelectExample {
7577

7678
/** Clears the query and the listbox value. */
7779
clear(): void {
78-
this.query.set('');
80+
this.comboboxInput()?.value.set('');
7981
this.listbox?.()?.values.set([]);
8082
}
8183

src/components-examples/aria/autocomplete/autocomplete-disabled/autocomplete-disabled-example.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<input
55
aria-label="Label dropdown"
66
placeholder="Select a country"
7-
[(ngModel)]="query"
87
ngComboboxInput
98
/>
109
</div>

src/components-examples/aria/autocomplete/autocomplete-highlight/autocomplete-highlight-example.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<input
55
aria-label="Label dropdown"
66
placeholder="Select a country"
7-
[(ngModel)]="query"
87
ngComboboxInput
98
/>
109
<button

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
ChangeDetectionStrategy,
1919
Component,
2020
computed,
21-
signal,
2221
viewChild,
2322
viewChildren,
2423
} from '@angular/core';
@@ -53,8 +52,11 @@ export class AutocompleteHighlightExample {
5352
/** A reference to the ng aria combobox. */
5453
combobox = viewChild<Combobox<string>>(Combobox);
5554

55+
/** A reference to the ng aria combobox input. */
56+
comboboxInput = viewChild<ComboboxInput>(ComboboxInput);
57+
5658
/** The query string used to filter the list of countries. */
57-
query = signal('');
59+
query = computed(() => this.comboboxInput()?.value() || '');
5860

5961
/** The list of countries filtered by the query. */
6062
countries = computed(() =>
@@ -73,7 +75,7 @@ export class AutocompleteHighlightExample {
7375

7476
/** Clears the query and the listbox value. */
7577
clear(): void {
76-
this.query.set('');
78+
this.comboboxInput()?.value.set('');
7779
this.listbox?.()?.values.set([]);
7880
}
7981

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<input
55
aria-label="Label dropdown"
66
placeholder="Select a country"
7-
[(ngModel)]="query"
87
ngComboboxInput
98
/>
109
<button

src/components-examples/aria/autocomplete/autocomplete-manual/autocomplete-manual-example.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
ChangeDetectionStrategy,
1919
Component,
2020
computed,
21-
signal,
2221
viewChild,
2322
viewChildren,
2423
} from '@angular/core';
@@ -53,8 +52,11 @@ export class AutocompleteManualExample {
5352
/** A reference to the ng aria combobox. */
5453
combobox = viewChild<Combobox<string>>(Combobox);
5554

55+
/** A reference to the ng aria combobox input. */
56+
comboboxInput = viewChild<ComboboxInput>(ComboboxInput);
57+
5658
/** The query string used to filter the list of countries. */
57-
query = signal('');
59+
query = computed(() => this.comboboxInput()?.value() || '');
5860

5961
/** The list of countries filtered by the query. */
6062
countries = computed(() =>
@@ -73,7 +75,7 @@ export class AutocompleteManualExample {
7375

7476
/** Clears the query and the listbox value. */
7577
clear(): void {
76-
this.query.set('');
78+
this.comboboxInput()?.value.set('');
7779
this.listbox?.()?.values.set([]);
7880
}
7981

0 commit comments

Comments
 (0)