Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/aria/private/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,11 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
select(opts: {item?: T; commit?: boolean; close?: boolean} = {}) {
const controls = this.listControls();

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

// Check if item is disabled before proceeding.
if (item?.disabled()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<input
aria-label="Label dropdown"
placeholder="Select a country"
[(ngModel)]="query"
ngComboboxInput
/>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ChangeDetectionStrategy,
Component,
computed,
signal,
viewChild,
viewChildren,
} from '@angular/core';
Expand Down Expand Up @@ -55,8 +54,11 @@ export class AutocompleteAutoSelectExample {
/** A reference to the ng aria combobox. */
combobox = viewChild<Combobox<string>>(Combobox);

/** A reference to the ng aria combobox input. */
comboboxInput = viewChild<ComboboxInput>(ComboboxInput);

/** The query string used to filter the list of countries. */
query = signal('');
query = computed(() => this.comboboxInput()?.value() || '');

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

/** Clears the query and the listbox value. */
clear(): void {
this.query.set('');
this.comboboxInput()?.value.set('');
this.listbox?.()?.values.set([]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<input
aria-label="Label dropdown"
placeholder="Select a country"
[(ngModel)]="query"
ngComboboxInput
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<input
aria-label="Label dropdown"
placeholder="Select a country"
[(ngModel)]="query"
ngComboboxInput
/>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ChangeDetectionStrategy,
Component,
computed,
signal,
viewChild,
viewChildren,
} from '@angular/core';
Expand Down Expand Up @@ -53,8 +52,11 @@ export class AutocompleteHighlightExample {
/** A reference to the ng aria combobox. */
combobox = viewChild<Combobox<string>>(Combobox);

/** A reference to the ng aria combobox input. */
comboboxInput = viewChild<ComboboxInput>(ComboboxInput);

/** The query string used to filter the list of countries. */
query = signal('');
query = computed(() => this.comboboxInput()?.value() || '');

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

/** Clears the query and the listbox value. */
clear(): void {
this.query.set('');
this.comboboxInput()?.value.set('');
this.listbox?.()?.values.set([]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<input
aria-label="Label dropdown"
placeholder="Select a country"
[(ngModel)]="query"
ngComboboxInput
/>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ChangeDetectionStrategy,
Component,
computed,
signal,
viewChild,
viewChildren,
} from '@angular/core';
Expand Down Expand Up @@ -53,8 +52,11 @@ export class AutocompleteManualExample {
/** A reference to the ng aria combobox. */
combobox = viewChild<Combobox<string>>(Combobox);

/** A reference to the ng aria combobox input. */
comboboxInput = viewChild<ComboboxInput>(ComboboxInput);

/** The query string used to filter the list of countries. */
query = signal('');
query = computed(() => this.comboboxInput()?.value() || '');

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

/** Clears the query and the listbox value. */
clear(): void {
this.query.set('');
this.comboboxInput()?.value.set('');
this.listbox?.()?.values.set([]);
}

Expand Down
Loading