@@ -129,8 +129,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
129
129
/** The subscription for closing actions (some are bound to document). */
130
130
private _closingActionsSubscription : Subscription ;
131
131
132
- /** Stream of escape keyboard events. */
133
- private _escapeEventStream = new Subject < void > ( ) ;
132
+ /** Stream of keyboard events that can close the panel . */
133
+ private _closeKeyEventStream = new Subject < void > ( ) ;
134
134
135
135
/** View -> model callback called when value changes */
136
136
_onChange : ( value : any ) => void = ( ) => { } ;
@@ -152,7 +152,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
152
152
153
153
ngOnDestroy ( ) {
154
154
this . _destroyPanel ( ) ;
155
- this . _escapeEventStream . complete ( ) ;
155
+ this . _closeKeyEventStream . complete ( ) ;
156
156
}
157
157
158
158
/** Whether or not the autocomplete panel is open. */
@@ -194,7 +194,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
194
194
return merge (
195
195
this . optionSelections ,
196
196
this . autocomplete . _keyManager . tabOut . pipe ( filter ( ( ) => this . _panelOpen ) ) ,
197
- this . _escapeEventStream ,
197
+ this . _closeKeyEventStream ,
198
198
this . _outsideClickStream ,
199
199
this . _overlayRef ?
200
200
this . _overlayRef . detachments ( ) . pipe ( filter ( ( ) => this . _panelOpen ) ) :
@@ -289,9 +289,11 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
289
289
_handleKeydown ( event : KeyboardEvent ) : void {
290
290
const keyCode = event . keyCode ;
291
291
292
- if ( keyCode === ESCAPE && this . panelOpen ) {
292
+ // Close when pressing ESCAPE or ALT + UP_ARROW, based on the a11y guidelines.
293
+ // See: https://www.w3.org/TR/wai-aria-practices-1.1/#textbox-keyboard-interaction
294
+ if ( this . panelOpen && ( keyCode === ESCAPE || ( keyCode === UP_ARROW && event . altKey ) ) ) {
293
295
this . _resetActiveItem ( ) ;
294
- this . _escapeEventStream . next ( ) ;
296
+ this . _closeKeyEventStream . next ( ) ;
295
297
event . stopPropagation ( ) ;
296
298
} else if ( this . activeOption && keyCode === ENTER && this . panelOpen ) {
297
299
this . activeOption . _selectViaInteraction ( ) ;
0 commit comments