@@ -10,7 +10,7 @@ import {FocusKeyManager} from '@angular/cdk/a11y';
1010import { Directionality } from '@angular/cdk/bidi' ;
1111import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1212import { SelectionModel } from '@angular/cdk/collections' ;
13- import { BACKSPACE , LEFT_ARROW , RIGHT_ARROW } from '@angular/cdk/keycodes' ;
13+ import { BACKSPACE } from '@angular/cdk/keycodes' ;
1414import { startWith } from 'rxjs/operators/startWith' ;
1515import {
1616 AfterContentInit ,
@@ -331,8 +331,10 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
331331 }
332332
333333 ngAfterContentInit ( ) : void {
334-
335- this . _keyManager = new FocusKeyManager < MatChip > ( this . chips ) . withWrap ( ) ;
334+ this . _keyManager = new FocusKeyManager < MatChip > ( this . chips )
335+ . withWrap ( )
336+ . withVerticalOrientation ( )
337+ . withHorizontalOrientation ( this . _dir ? this . _dir . value : 'ltr' ) ;
336338
337339 // Prevents the chip list from capturing focus and redirecting
338340 // it back to the first chip when the user tabs out.
@@ -450,35 +452,16 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
450452 * Pass events to the keyboard manager. Available here for tests.
451453 */
452454 _keydown ( event : KeyboardEvent ) {
453- let code = event . keyCode ;
454- let target = event . target as HTMLElement ;
455- let isInputEmpty = this . _isInputEmpty ( target ) ;
456- let isRtl = this . _dir && this . _dir . value == 'rtl' ;
457-
458- let isPrevKey = ( code === ( isRtl ? RIGHT_ARROW : LEFT_ARROW ) ) ;
459- let isNextKey = ( code === ( isRtl ? LEFT_ARROW : RIGHT_ARROW ) ) ;
460- let isBackKey = code === BACKSPACE ;
455+ const target = event . target as HTMLElement ;
456+
461457 // If they are on an empty input and hit backspace, focus the last chip
462- if ( isInputEmpty && isBackKey ) {
458+ if ( this . _isInputEmpty ( target ) && event . keyCode === BACKSPACE ) {
463459 this . _keyManager . setLastItemActive ( ) ;
464460 event . preventDefault ( ) ;
465- return ;
466- }
467-
468- // If they are on a chip, check for space/left/right, otherwise pass to our key manager (like
469- // up/down keys)
470- if ( target && target . classList . contains ( 'mat-chip' ) ) {
471- if ( isPrevKey ) {
472- this . _keyManager . setPreviousItemActive ( ) ;
473- event . preventDefault ( ) ;
474- } else if ( isNextKey ) {
475- this . _keyManager . setNextItemActive ( ) ;
476- event . preventDefault ( ) ;
477- } else {
478- this . _keyManager . onKeydown ( event ) ;
479- }
461+ } else {
462+ this . _keyManager . onKeydown ( event ) ;
463+ this . stateChanges . next ( ) ;
480464 }
481- this . stateChanges . next ( ) ;
482465 }
483466
484467
0 commit comments