Skip to content
Merged
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/simple-combobox/simple-combobox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ describe('Combobox', () => {
[alwaysExpanded]="alwaysExpanded()"
[tabindex]="tabIndex()"
(focusout)="onBlur()"
(click)="popupExpanded.set(true)"
/>

<ng-template ngComboboxPopup [combobox]="combobox">
Expand Down Expand Up @@ -1556,6 +1557,7 @@ class ComboboxGridExample {
(input)="onInput()"
[disabled]="readonly()"
(focusout)="onBlur()"
(click)="combobox.expanded.set(true)"
/>

<ng-template ngComboboxPopup [combobox]="combobox">
Expand Down Expand Up @@ -1619,6 +1621,7 @@ class ComboboxListboxAutoSelectExample {
[(expanded)]="popupExpanded"
[inlineSuggestion]="value()[0] || options()[0]"
[disabled]="readonly()"
(click)="popupExpanded.set(true)"
/>

<ng-template ngComboboxPopup [combobox]="combobox">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div #origin class="example-combobox-input-container">
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search states..."
[(value)]="searchString" [(expanded)]="popupExpanded" />
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
placeholder="Select a country"
[(value)]="searchString"
[(expanded)]="popupExpanded"
(click)="popupExpanded.set(true)"
/>
<button
class="example-clear-button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
<div class="example-combobox-container">
<div #origin class="example-autocomplete">
<span class="example-search-icon material-symbols-outlined" translate="no">search</span>
<input
ngCombobox
#combobox="ngCombobox"
aria-label="Label dropdown"
placeholder="Select a country"
[(value)]="searchString"
[(expanded)]="popupExpanded"
[inlineSuggestion]="selectedOption()[0] || countries()[0]"
/>
<button
class="example-clear-button"
aria-label="Clear"
(keydown)="onKeydown($event)"
(click)="clear()"
>
<input ngCombobox #combobox="ngCombobox" aria-label="Label dropdown" placeholder="Select a country"
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)"
(keydown.arrowdown)="navigated.set(true)" (keydown.arrowup)="navigated.set(true)"
[inlineSuggestion]="(searchString() || navigated()) ? selectedOption()[0] : undefined" />
<button class="example-clear-button" aria-label="Clear" (keydown)="onKeydown($event)" (click)="clear()">
<span aria-hidden="true" class="example-clear-icon material-symbols-outlined">close</span>
</button>
</div>
Expand All @@ -24,23 +14,24 @@
{{countries().length === 0 ? 'No results found for ' + query() : ''}}
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true">
<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}"
[cdkConnectedOverlayOpen]="true">
<ng-template ngComboboxPopup [combobox]="combobox">
<div class="example-popup">
@if (countries().length === 0) {
<div class="example-no-results">No results found</div>
<div class="example-no-results">No results found</div>
}

<div ngListbox ngComboboxWidget focusMode="activedescendant" [tabindex]="-1" [(value)]="selectedOption"
<div ngListbox ngComboboxWidget focusMode="activedescendant" [tabindex]="-1" selectionMode="follow" [(value)]="selectedOption"
(click)="onCommit()" (keydown.enter)="onCommit()">
@for (country of countries(); track country) {
<div ngOption [value]="country" [label]="country" [disabled]="country === 'Brazil'">
<span class="example-option-label">{{country}}</span>
<span class="example-check-icon material-symbols-outlined" translate="no">check</span>
</div>
<div ngOption [value]="country" [label]="country" [disabled]="country === 'Brazil'">
<span class="example-option-label">{{country}}</span>
<span class="example-check-icon material-symbols-outlined" translate="no">check</span>
</div>
}
</div>
</div>
</ng-template>
</ng-template>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ChangeDetectionStrategy,
Component,
computed,
effect,
signal,
viewChild,
} from '@angular/core';
Expand All @@ -36,6 +37,7 @@ export class SimpleComboboxAutocompleteHighlightExample {
popupExpanded = signal(false);
searchString = signal('');
selectedOption = signal<string[]>([]);
navigated = signal(false);

/** The query string used to filter the list of countries. */
query = computed(() => this.searchString());
Expand All @@ -49,6 +51,12 @@ export class SimpleComboboxAutocompleteHighlightExample {
afterRenderEffect(() => {
this.listbox()?.scrollActiveItemIntoView();
});

effect(() => {
if (!this.popupExpanded()) {
this.navigated.set(false);
}
});
}

/** Clears the query and the listbox value. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div #origin class="example-autocomplete">
<span class="example-search-icon material-symbols-outlined" translate="no">search</span>
<input ngCombobox #combobox="ngCombobox" aria-label="Label dropdown" placeholder="Select a country"
[(value)]="searchString" [(expanded)]="popupExpanded" />
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
<button class="example-clear-button" aria-label="Clear" (keydown)="onKeydown($event)" (click)="clear()">
<span aria-hidden="true" class="example-clear-icon material-symbols-outlined">close</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span class="material-symbols-outlined example-icon example-search-icon">calendar_month</span>
<input #comboboxInput ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Pick a date..."
[(value)]="selection" [(expanded)]="popupExpanded" aria-describedby="date-format-hint"
(keydown)="onInputKeydown($event)" />
(keydown)="onInputKeydown($event)" (click)="popupExpanded.set(true)" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: false}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div #origin class="example-combobox-input-container">
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search..."
[(value)]="searchString" [(expanded)]="popupExpanded" (blur)="onBlur()" />
[(value)]="searchString" [(expanded)]="popupExpanded" (blur)="onBlur()" (click)="popupExpanded.set(true)" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
<div #origin class="example-combobox-input-container">
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search states..."
[(value)]="searchString" [(expanded)]="popupExpanded"
[inlineSuggestion]="selectedOption()[0] || options()[0]?.name" />
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)"
(keydown.arrowdown)="navigated.set(true)" (keydown.arrowup)="navigated.set(true)"
[inlineSuggestion]="(searchString() || navigated()) ? selectedOption()[0] : undefined" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"
[cdkConnectedOverlayDisableClose]="true">
<ng-template ngComboboxPopup [combobox]="combobox">
<div #listbox="ngListbox" ngListbox ngComboboxWidget class="example-listbox example-popup" focusMode="activedescendant"
[tabindex]="-1" [(value)]="selectedOption" (click)="onCommit()" (keydown.enter)="onCommit()"
[activeDescendant]="listbox.activeDescendant()">
<div #listbox="ngListbox" ngListbox ngComboboxWidget class="example-listbox example-popup"
focusMode="activedescendant" [tabindex]="-1" [(value)]="selectedOption" (click)="onCommit()"
(keydown.enter)="onCommit()" [activeDescendant]="listbox.activeDescendant()">
@for (option of options(); track option.name) {
<div class="example-option example-selectable example-stateful" ngOption [value]="option.name" [label]="option.name"
[disabled]="option.disabled">
<div class="example-option example-selectable example-stateful" ngOption [value]="option.name"
[label]="option.name" [disabled]="option.disabled">
<span>{{option.name}}</span>
<span aria-hidden="true" class="material-symbols-outlined example-icon example-selected-icon">check</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

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

options = computed(() =>
states.filter(state => state.name.toLowerCase().startsWith(this.searchString().toLowerCase())),
Expand All @@ -33,6 +34,12 @@ export class SimpleComboboxHighlightExample {
afterRenderEffect(() => {
this.listbox()?.scrollActiveItemIntoView();
});

effect(() => {
if (!this.popupExpanded()) {
this.navigated.set(false);
}
});
}

onCommit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div #origin class="example-combobox-input-container">
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search..."
[(value)]="searchString" [(expanded)]="popupExpanded" />
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div #origin class="example-combobox-input-container">
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search..."
[(value)]="searchString" [(expanded)]="popupExpanded" />
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
<div #origin class="example-combobox-input-container">
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search..."
[(value)]="searchString" [(expanded)]="popupExpanded"
[inlineSuggestion]="selectedValues()[0] || firstMatchingOption()" />
[(value)]="searchString" [(expanded)]="popupExpanded" (click)="popupExpanded.set(true)"
(keydown.arrowdown)="navigated.set(true)" (keydown.arrowup)="navigated.set(true)"
[inlineSuggestion]="(searchString() || navigated()) ? selectedValues()[0] : undefined" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}" [cdkConnectedOverlayOpen]="true"
[cdkConnectedOverlayDisableClose]="true">
<ng-template ngComboboxPopup [combobox]="combobox" popupType="tree">
<div class="example-popover">
<ul ngTree ngComboboxWidget class="example-tree" focusMode="activedescendant" [tabindex]="-1"
selectionMode="explicit" [(value)]="selectedValues" (click)="onCommit()" (keydown.enter)="onCommit()"
#tree="ngTree" [activeDescendant]="tree.activeDescendant()">
<ng-template [ngTemplateOutlet]="treeNodes"
[ngTemplateOutletContext]="{nodes: filteredGroups(), parent: tree}" />
</ul>
</div>
<ul ngTree ngComboboxWidget class="example-tree example-popup" focusMode="activedescendant" [tabindex]="-1"
selectionMode="follow" [(value)]="selectedValues" (click)="onCommit()" (keydown.enter)="onCommit()"
#tree="ngTree" [activeDescendant]="tree.activeDescendant()">
<ng-template [ngTemplateOutlet]="treeNodes"
[ngTemplateOutletContext]="{nodes: filteredGroups(), parent: tree}" />
</ul>
</ng-template>
</ng-template>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Component,
afterRenderEffect,
computed,
effect,
signal,
viewChild,
untracked,
Expand Down Expand Up @@ -49,6 +50,7 @@ export class SimpleComboboxTreeHighlightExample {
popupExpanded = signal(false);
searchString = signal('');
selectedValues = signal<string[]>([]);
navigated = signal(false);

readonly dataSource = signal(FOOD_DATA);

Expand All @@ -66,6 +68,12 @@ export class SimpleComboboxTreeHighlightExample {
});
}
});

effect(() => {
if (!this.popupExpanded()) {
this.navigated.set(false);
}
});
}

filteredData = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div #origin class="example-combobox-input-container">
<span class="material-symbols-outlined example-icon example-search-icon">search</span>
<input ngCombobox #combobox="ngCombobox" class="example-combobox-input" placeholder="Search..." [(value)]="searchString"
[(expanded)]="popupExpanded" />
[(expanded)]="popupExpanded" (click)="popupExpanded.set(true)" />
</div>

<ng-template [cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}"
Expand Down
2 changes: 1 addition & 1 deletion src/dev-app/aria-combobox/combobox-demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
min-width: 350px;
width: 350px;
padding: 20px 0;
}

Expand Down
Loading