@@ -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 ,
@@ -331,8 +331,10 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
331
331
}
332
332
333
333
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' ) ;
336
338
337
339
// Prevents the chip list from capturing focus and redirecting
338
340
// it back to the first chip when the user tabs out.
@@ -450,35 +452,16 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo
450
452
* Pass events to the keyboard manager. Available here for tests.
451
453
*/
452
454
_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
+
461
457
// 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 ) {
463
459
this . _keyManager . setLastItemActive ( ) ;
464
460
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 ( ) ;
480
464
}
481
- this . stateChanges . next ( ) ;
482
465
}
483
466
484
467
0 commit comments