@@ -3,13 +3,15 @@ import {Direction, Directionality} from '@angular/cdk/bidi';
3
3
import {
4
4
BACKSPACE ,
5
5
DELETE ,
6
+ DOWN_ARROW ,
6
7
END ,
7
8
ENTER ,
8
9
HOME ,
9
10
LEFT_ARROW ,
10
11
RIGHT_ARROW ,
11
12
SPACE ,
12
13
TAB ,
14
+ UP_ARROW ,
13
15
} from '@angular/cdk/keycodes' ;
14
16
import {
15
17
createKeyboardEvent ,
@@ -309,6 +311,48 @@ describe('MDC-based MatChipGrid', () => {
309
311
. withContext ( 'Expected focused item not to have changed.' )
310
312
. toBe ( previousActiveElement ) ;
311
313
} ) ;
314
+
315
+ it ( 'should focus primary action in next row when pressing DOWN ARROW on primary action' , ( ) => {
316
+ chips . first . focus ( ) ;
317
+ expect ( document . activeElement ) . toBe ( primaryActions [ 0 ] ) ;
318
+
319
+ dispatchKeyboardEvent ( primaryActions [ 0 ] , 'keydown' , DOWN_ARROW ) ;
320
+ fixture . detectChanges ( ) ;
321
+
322
+ expect ( document . activeElement ) . toBe ( primaryActions [ 1 ] ) ;
323
+ } ) ;
324
+
325
+ it ( 'should focus primary action in previous row when pressing UP ARROW on primary action' , ( ) => {
326
+ const lastIndex = primaryActions . length - 1 ;
327
+ chips . last . focus ( ) ;
328
+ expect ( document . activeElement ) . toBe ( primaryActions [ lastIndex ] ) ;
329
+
330
+ dispatchKeyboardEvent ( primaryActions [ lastIndex ] , 'keydown' , UP_ARROW ) ;
331
+ fixture . detectChanges ( ) ;
332
+
333
+ expect ( document . activeElement ) . toBe ( primaryActions [ lastIndex - 1 ] ) ;
334
+ } ) ;
335
+
336
+ it ( 'should focus(trailing action in next row when pressing DOWN ARROW on(trailing action' , ( ) => {
337
+ trailingActions [ 0 ] . focus ( ) ;
338
+ expect ( document . activeElement ) . toBe ( trailingActions [ 0 ] ) ;
339
+
340
+ dispatchKeyboardEvent ( trailingActions [ 0 ] , 'keydown' , DOWN_ARROW ) ;
341
+ fixture . detectChanges ( ) ;
342
+
343
+ expect ( document . activeElement ) . toBe ( trailingActions [ 1 ] ) ;
344
+ } ) ;
345
+
346
+ it ( 'should focus trailing action in previous row when pressing UP ARROW on trailing action' , ( ) => {
347
+ const lastIndex = trailingActions . length - 1 ;
348
+ trailingActions [ lastIndex ] . focus ( ) ;
349
+ expect ( document . activeElement ) . toBe ( trailingActions [ lastIndex ] ) ;
350
+
351
+ dispatchKeyboardEvent ( trailingActions [ lastIndex ] , 'keydown' , UP_ARROW ) ;
352
+ fixture . detectChanges ( ) ;
353
+
354
+ expect ( document . activeElement ) . toBe ( trailingActions [ lastIndex - 1 ] ) ;
355
+ } ) ;
312
356
} ) ;
313
357
314
358
describe ( 'RTL' , ( ) => {
@@ -1034,11 +1078,8 @@ describe('MDC-based MatChipGrid', () => {
1034
1078
template : `
1035
1079
<mat-chip-grid [tabIndex]="tabIndex" [role]="role" #chipGrid>
1036
1080
@for (i of chips; track i) {
1037
- <mat-chip-row
1038
- [editable]="editable">
1039
- {{name}} {{i + 1}}
1040
- </mat-chip-row>
1041
- }
1081
+ <mat-chip-row [editable]="editable">{{name}} {{i + 1}}</mat-chip-row>
1082
+ }
1042
1083
</mat-chip-grid>
1043
1084
<input name="test" [matChipInputFor]="chipGrid"/>` ,
1044
1085
} )
@@ -1056,8 +1097,8 @@ class StandardChipGrid {
1056
1097
<mat-label>Add a chip</mat-label>
1057
1098
<mat-chip-grid #chipGrid>
1058
1099
@for (chip of chips; track chip) {
1059
- <mat-chip-row (removed)="remove(chip)">{{chip}}</mat-chip-row>
1060
- }
1100
+ <mat-chip-row (removed)="remove(chip)">{{chip}}</mat-chip-row>
1101
+ }
1061
1102
</mat-chip-grid>
1062
1103
<input name="test" [matChipInputFor]="chipGrid"/>
1063
1104
</mat-form-field>
@@ -1081,10 +1122,10 @@ class FormFieldChipGrid {
1081
1122
<mat-label>New food...</mat-label>
1082
1123
<mat-chip-grid #chipGrid placeholder="Food" [formControl]="control">
1083
1124
@for (food of foods; track food) {
1084
- <mat-chip-row [value]="food.value" (removed)="remove(food)">
1085
- {{ food.viewValue }}
1086
- </mat-chip-row>
1087
- }
1125
+ <mat-chip-row [value]="food.value" (removed)="remove(food)">
1126
+ {{ food.viewValue }}
1127
+ </mat-chip-row>
1128
+ }
1088
1129
</mat-chip-grid>
1089
1130
<input
1090
1131
[matChipInputFor]="chipGrid"
@@ -1143,10 +1184,8 @@ class InputChipGrid {
1143
1184
<mat-form-field>
1144
1185
<mat-chip-grid #chipGrid [formControl]="formControl">
1145
1186
@for (food of foods; track food) {
1146
- <mat-chip-row [value]="food.value">
1147
- {{food.viewValue}}
1148
- </mat-chip-row>
1149
- }
1187
+ <mat-chip-row [value]="food.value">{{food.viewValue}}</mat-chip-row>
1188
+ }
1150
1189
</mat-chip-grid>
1151
1190
<input name="test" [matChipInputFor]="chipGrid"/>
1152
1191
<mat-hint>Please select a chip, or type to add a new chip</mat-hint>
@@ -1179,8 +1218,8 @@ class ChipGridWithFormErrorMessages {
1179
1218
template : `
1180
1219
<mat-chip-grid #chipGrid>
1181
1220
@for (i of numbers; track i) {
1182
- <mat-chip-row (removed)="remove(i)">{{i}}</mat-chip-row>
1183
- }
1221
+ <mat-chip-row (removed)="remove(i)">{{i}}</mat-chip-row>
1222
+ }
1184
1223
<input name="test" [matChipInputFor]="chipGrid"/>
1185
1224
</mat-chip-grid>` ,
1186
1225
animations : [
@@ -1208,11 +1247,11 @@ class StandardChipGridWithAnimations {
1208
1247
<mat-form-field>
1209
1248
<mat-chip-grid #chipGrid>
1210
1249
@for (i of chips; track i) {
1211
- <mat-chip-row [value]="i" (removed)="removeChip($event)">
1212
- Chip {{i + 1}}
1213
- <span matChipRemove>Remove</span>
1214
- </mat-chip-row>
1215
- }
1250
+ <mat-chip-row [value]="i" (removed)="removeChip($event)">
1251
+ Chip {{i + 1}}
1252
+ <span matChipRemove>Remove</span>
1253
+ </mat-chip-row>
1254
+ }
1216
1255
</mat-chip-grid>
1217
1256
<input name="test" [matChipInputFor]="chipGrid"/>
1218
1257
</mat-form-field>
0 commit comments