-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(aria/combobox): forward advanced combination keys in SimpleComboboxPattern #33196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ox/simple-combobox-editable-multiselect/simple-combobox-editable-multiselect-example.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <div class="example-combobox-container" ngCombobox #combobox="ngCombobox" [(expanded)]="popupExpanded"> | ||
| <div #origin class="example-combobox-input-container"> | ||
| <input class="example-combobox-input example-dialog-input" placeholder="Select countries..." [value]="value()" | ||
| [readonly]="true" [tabindex]="-1" /> | ||
| <span class="material-symbols-outlined example-icon example-arrow-icon">arrow_drop_down</span> | ||
| </div> | ||
|
|
||
| <ng-template [cdkConnectedOverlay]="{origin: combobox.element, usePopover: 'inline', matchWidth: true}" | ||
| [cdkConnectedOverlayOpen]="popupExpanded()" [cdkConnectedOverlayDisableClose]="false" | ||
| (overlayOutsideClick)="popupExpanded.set(false)"> | ||
| <ng-template ngComboboxPopup [combobox]="combobox" popupType="dialog"> | ||
|
|
||
| <div class="example-popover"> | ||
| <div class="example-dialog" ngComboboxWidget> | ||
| <div class="example-combobox-container"> | ||
| <div class="example-combobox-input-container"> | ||
| <span class="material-symbols-outlined example-icon example-search-icon">search</span> | ||
| <input ngCombobox #innerCombobox="ngCombobox" #searchInput class="example-combobox-input" | ||
| placeholder="Search..." [(ngModel)]="searchString" [alwaysExpanded]="true" | ||
| (keydown.escape)="onSearchEscape($event)" /> | ||
| </div> | ||
|
|
||
| <div aria-live="polite" class="cdk-visually-hidden"> | ||
| {{countries().length === 0 ? 'No results found for ' + searchString() : ''}} | ||
| </div> | ||
|
|
||
| <ng-template ngComboboxPopup [combobox]="innerCombobox"> | ||
| <div class="example-popup example-popup-no-margin"> | ||
| @if (countries().length === 0) { | ||
| <div class="example-no-results">No results found</div> | ||
| } | ||
| <div #listbox="ngListbox" ngListbox [multi]="true" ngComboboxWidget class="example-listbox" focusMode="activedescendant" | ||
| tabindex="-1" selectionMode="explicit" [(value)]="selectedOptions" (click)="onCommit()" | ||
| (keydown.enter)="onCommit()" [activeDescendant]="listbox.activeDescendant()" | ||
| [class.example-empty]="countries().length === 0"> | ||
| @for (country of countries(); track country) { | ||
| <div class="example-option example-selectable example-stateful" ngOption [value]="country" | ||
| [label]="country"> | ||
| <span>{{country}}</span> | ||
| <span aria-hidden="true" | ||
| class="material-symbols-outlined example-icon example-selected-icon">check</span> | ||
| </div> | ||
| } | ||
| </div> | ||
| </div> | ||
| </ng-template> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </ng-template> | ||
| </ng-template> | ||
| </div> |
100 changes: 100 additions & 0 deletions
100
...obox/simple-combobox-editable-multiselect/simple-combobox-editable-multiselect-example.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * @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, | ||
| untracked, | ||
| viewChild, | ||
| ElementRef, | ||
| } from '@angular/core'; | ||
| import {COUNTRIES} from '../countries'; | ||
| import {OverlayModule} from '@angular/cdk/overlay'; | ||
| import {FormsModule} from '@angular/forms'; | ||
|
|
||
| /** @title Editable multiselectable combobox with a dialog layout. */ | ||
| @Component({ | ||
| selector: 'simple-combobox-editable-multiselect-example', | ||
| templateUrl: 'simple-combobox-editable-multiselect-example.html', | ||
| styleUrl: '../simple-combobox-example.css', | ||
| imports: [Combobox, ComboboxPopup, ComboboxWidget, Listbox, Option, OverlayModule, FormsModule], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class SimpleComboboxEditableMultiselectExample { | ||
| readonly listbox = viewChild(Listbox); | ||
| readonly combobox = viewChild(Combobox); | ||
| readonly searchInput = viewChild<ElementRef<HTMLInputElement>>('searchInput'); | ||
|
|
||
| popupExpanded = signal(false); | ||
| searchString = signal(''); | ||
| selectedOptions = signal<string[]>([]); | ||
|
|
||
| /** The display text for the primary readonly trigger input. */ | ||
| value = computed(() => { | ||
| const current = this.selectedOptions(); | ||
| if (current.length === 0) return ''; | ||
| if (current.length === 1) return current[0]; | ||
| return `${current[0]} + ${current.length - 1} more`; | ||
| }); | ||
|
|
||
| /** The list of countries filtered by the inner search input query. */ | ||
| countries = computed(() => { | ||
| const currentQuery = this.searchString().toLowerCase(); | ||
| return COUNTRIES.filter(country => country.toLowerCase().startsWith(currentQuery)); | ||
| }); | ||
|
|
||
| constructor() { | ||
| // Automatically auto-focus the inner search text field when the dialog expands | ||
| afterRenderEffect(() => { | ||
| if (this.popupExpanded()) { | ||
| untracked(() => { | ||
| setTimeout(() => { | ||
| this.searchInput()?.nativeElement.focus(); | ||
| }); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| afterRenderEffect(() => { | ||
| if (this.popupExpanded()) { | ||
| this.listbox()?.scrollActiveItemIntoView(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** Clears the search query and all selected options. */ | ||
| clear(): void { | ||
| this.searchString.set(''); | ||
| this.selectedOptions.set([]); | ||
| } | ||
|
|
||
| /** Keeps focus inside the dialog when selection changes. */ | ||
| onCommit() { | ||
| this.searchString.set(''); | ||
| } | ||
|
|
||
| /** Dismisses the dialog overlay on Escape key. */ | ||
| onSearchEscape(event: Event) { | ||
| this.popupExpanded.set(false); | ||
| this.combobox()?.element.focus(); | ||
| } | ||
|
|
||
| /** Handles keydown events on the clear button. */ | ||
| onKeydown(event: KeyboardEvent): void { | ||
| if (event.key === 'Enter') { | ||
| this.clear(); | ||
| this.popupExpanded.set(false); | ||
| event.stopPropagation(); | ||
| } | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
...mbobox/simple-combobox-multiselect-dialog/simple-combobox-multiselect-dialog-example.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <div class="example-combobox-container" ngCombobox #combobox="ngCombobox" [(expanded)]="popupExpanded"> | ||
| <div #origin class="example-combobox-input-container"> | ||
| <input class="example-combobox-input example-dialog-input" placeholder="Select countries..." [value]="value()" | ||
| [readonly]="true" [tabindex]="-1" /> | ||
| <span class="material-symbols-outlined example-icon example-arrow-icon">arrow_drop_down</span> | ||
| </div> | ||
|
|
||
| <ng-template [cdkConnectedOverlay]="{origin: combobox.element, usePopover: 'inline', matchWidth: true}" | ||
| [cdkConnectedOverlayOpen]="popupExpanded()" [cdkConnectedOverlayDisableClose]="false" | ||
| (overlayOutsideClick)="popupExpanded.set(false)"> | ||
| <ng-template ngComboboxPopup [combobox]="combobox" popupType="dialog"> | ||
|
|
||
| <div class="example-popover"> | ||
| <div class="example-dialog" ngComboboxWidget> | ||
| <div class="example-combobox-container"> | ||
| <div class="example-combobox-input-container"> | ||
| <span class="material-symbols-outlined example-icon example-search-icon">search</span> | ||
| <input ngCombobox #innerCombobox="ngCombobox" #searchInput class="example-combobox-input" | ||
| placeholder="Search..." [(ngModel)]="searchString" [alwaysExpanded]="true" | ||
| (keydown.escape)="onSearchEscape($event)" /> | ||
| </div> | ||
|
|
||
| <div aria-live="polite" class="cdk-visually-hidden"> | ||
| {{countries().length === 0 ? 'No results found for ' + searchString() : ''}} | ||
| </div> | ||
|
|
||
| <ng-template ngComboboxPopup [combobox]="innerCombobox"> | ||
| <div class="example-popup example-popup-no-margin"> | ||
| @if (countries().length === 0) { | ||
| <div class="example-no-results">No results found</div> | ||
| } | ||
| <div #listbox="ngListbox" ngListbox [multi]="true" ngComboboxWidget class="example-listbox" focusMode="activedescendant" | ||
| tabindex="-1" selectionMode="explicit" [(value)]="selectedOptions" (click)="onCommit()" | ||
| (keydown.enter)="onCommit()" [activeDescendant]="listbox.activeDescendant()" | ||
| [class.example-empty]="countries().length === 0"> | ||
| @for (country of countries(); track country) { | ||
| <div class="example-option example-selectable example-stateful" ngOption [value]="country" | ||
| [label]="country"> | ||
| <span>{{country}}</span> | ||
| <span aria-hidden="true" | ||
| class="material-symbols-outlined example-icon example-selected-icon">check</span> | ||
| </div> | ||
| } | ||
| </div> | ||
| </div> | ||
| </ng-template> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </ng-template> | ||
| </ng-template> | ||
| </div> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit curious about how to use it in a real example, when multiple options are selected, how will the input box change. Do we want to ship along with an example in dev-app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it'd be nice to see if other Aria directives handle the key combo automatically. E.g. listbox, tree, grid, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on what you mean for tree and grid ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to see examples of how multi-selectable works for Tree and Grid when used in Combobox with the combo keys.