@@ -320,6 +320,20 @@ describe('MatChipList', () => {
320320 manager = chipListInstance . _keyManager ;
321321 } ) ;
322322
323+ it ( 'should maintain focus if the active chip is deleted' , ( ) => {
324+ const secondChip = fixture . nativeElement . querySelectorAll ( '.mat-chip' ) [ 1 ] ;
325+
326+ secondChip . focus ( ) ;
327+ fixture . detectChanges ( ) ;
328+
329+ expect ( chipListInstance . chips . toArray ( ) . findIndex ( chip => chip . _hasFocus ) ) . toBe ( 1 ) ;
330+
331+ dispatchKeyboardEvent ( secondChip , 'keydown' , DELETE ) ;
332+ fixture . detectChanges ( ) ;
333+
334+ expect ( chipListInstance . chips . toArray ( ) . findIndex ( chip => chip . _hasFocus ) ) . toBe ( 1 ) ;
335+ } ) ;
336+
323337 describe ( 'when the input has focus' , ( ) => {
324338
325339 it ( 'should not focus the last chip when press DELETE' , ( ) => {
@@ -1073,15 +1087,22 @@ class StandardChipList {
10731087 <mat-form-field>
10741088 <mat-label>Add a chip</mat-label>
10751089 <mat-chip-list #chipList>
1076- <mat-chip>Chip 1</mat-chip>
1077- <mat-chip>Chip 1</mat-chip>
1078- <mat-chip>Chip 1</mat-chip>
1090+ <mat-chip *ngFor="let chip of chips" (removed)="remove(chip)">{{chip}}</mat-chip>
10791091 </mat-chip-list>
10801092 <input name="test" [matChipInputFor]="chipList"/>
10811093 </mat-form-field>
10821094 `
10831095} )
10841096class FormFieldChipList {
1097+ chips = [ 'Chip 0' , 'Chip 1' , 'Chip 2' ] ;
1098+
1099+ remove ( chip : string ) {
1100+ const index = this . chips . indexOf ( chip ) ;
1101+
1102+ if ( index > - 1 ) {
1103+ this . chips . splice ( index , 1 ) ;
1104+ }
1105+ }
10851106}
10861107
10871108
0 commit comments