@@ -35,6 +35,7 @@ import {FormControl, FormsModule, NgForm, ReactiveFormsModule, Validators} from
35
35
import { MatFormFieldModule } from '@angular/material/form-field' ;
36
36
import { By } from '@angular/platform-browser' ;
37
37
import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
38
+ import { Subject } from 'rxjs' ;
38
39
import { MatInputModule } from '../input/index' ;
39
40
import { MatChip } from './chip' ;
40
41
import { MatChipInputEvent } from './chip-input' ;
@@ -50,6 +51,7 @@ describe('MatChipList', () => {
50
51
let chips : QueryList < MatChip > ;
51
52
let manager : FocusKeyManager < MatChip > ;
52
53
let zone : MockNgZone ;
54
+ let dirChange : Subject < Direction > ;
53
55
54
56
describe ( 'StandardChipList' , ( ) => {
55
57
describe ( 'basic behaviors' , ( ) => {
@@ -422,6 +424,38 @@ describe('MatChipList', () => {
422
424
expect ( chipListInstance . _tabIndex ) . toBe ( 4 , 'Expected tabIndex to be reset back to 4' ) ;
423
425
} ) ) ;
424
426
} ) ;
427
+
428
+ it ( 'should account for the direction changing' , ( ) => {
429
+ setupStandardList ( ) ;
430
+ manager = chipListInstance . _keyManager ;
431
+
432
+ let nativeChips = chipListNativeElement . querySelectorAll ( 'mat-chip' ) ;
433
+ let firstNativeChip = nativeChips [ 0 ] as HTMLElement ;
434
+
435
+ let RIGHT_EVENT : KeyboardEvent =
436
+ createKeyboardEvent ( 'keydown' , RIGHT_ARROW , firstNativeChip ) ;
437
+ let array = chips . toArray ( ) ;
438
+ let firstItem = array [ 0 ] ;
439
+
440
+ firstItem . focus ( ) ;
441
+ expect ( manager . activeItemIndex ) . toBe ( 0 ) ;
442
+
443
+ chipListInstance . _keydown ( RIGHT_EVENT ) ;
444
+ chipListInstance . _blur ( ) ;
445
+ fixture . detectChanges ( ) ;
446
+
447
+ expect ( manager . activeItemIndex ) . toBe ( 1 ) ;
448
+
449
+ dirChange . next ( 'rtl' ) ;
450
+ fixture . detectChanges ( ) ;
451
+
452
+ chipListInstance . _keydown ( RIGHT_EVENT ) ;
453
+ chipListInstance . _blur ( ) ;
454
+ fixture . detectChanges ( ) ;
455
+
456
+ expect ( manager . activeItemIndex ) . toBe ( 0 ) ;
457
+ } ) ;
458
+
425
459
} ) ;
426
460
} ) ;
427
461
@@ -1239,8 +1273,12 @@ describe('MatChipList', () => {
1239
1273
}
1240
1274
1241
1275
function setupStandardList ( direction : Direction = 'ltr' ) {
1276
+ dirChange = new Subject ( ) ;
1242
1277
fixture = createComponent ( StandardChipList , [ {
1243
- provide : Directionality , useFactory : ( ) => ( { value : direction . toLowerCase ( ) } )
1278
+ provide : Directionality , useFactory : ( ) => ( {
1279
+ value : direction . toLowerCase ( ) ,
1280
+ change : dirChange
1281
+ } )
1244
1282
} ] ) ;
1245
1283
fixture . detectChanges ( ) ;
1246
1284
0 commit comments