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