@@ -225,6 +225,34 @@ describe('IgxGrid - Cell selection #grid', () => {
225
225
GridSelectionFunctions . verifySelectedRange ( grid , 0 , 0 , 0 , 0 , 2 , 3 ) ;
226
226
} ) ;
227
227
228
+ it ( 'Should be able to select cells correctly when focus is returned to the grid' , async ( ) => {
229
+ const firstCell = grid . gridAPI . get_cell_by_index ( 1 , 'ParentID' ) ;
230
+ const secondCell = grid . gridAPI . get_cell_by_index ( 2 , 'Name' ) ;
231
+
232
+ UIInteractions . simulateClickAndSelectEvent ( firstCell ) ;
233
+ fix . detectChanges ( ) ;
234
+
235
+ GridSelectionFunctions . verifyCellSelected ( firstCell ) ;
236
+ expect ( grid . selectedCells . length ) . toBe ( 1 ) ;
237
+
238
+ UIInteractions . simulateClickAndSelectEvent ( firstCell , false , true ) ;
239
+ fix . detectChanges ( ) ;
240
+
241
+ expect ( grid . selectedCells . length ) . toBe ( 0 ) ;
242
+
243
+ grid . navigation . lastActiveNode = grid . navigation . activeNode ;
244
+ grid . navigation . activeNode = null ;
245
+ fix . detectChanges ( ) ;
246
+ grid . tbody . nativeElement . focus ( ) ;
247
+ fix . detectChanges ( ) ;
248
+
249
+ UIInteractions . simulateClickAndSelectEvent ( secondCell , false , true ) ;
250
+ fix . detectChanges ( ) ;
251
+ GridSelectionFunctions . verifyCellSelected ( firstCell , false ) ;
252
+ GridSelectionFunctions . verifyCellSelected ( secondCell , true ) ;
253
+ expect ( grid . selectedCells . length ) . toBe ( 1 ) ;
254
+ } ) ;
255
+
228
256
it ( 'Should be able to select range when click on a cell and hold Shift key and click on another Cell' , ( ) => {
229
257
const firstCell = grid . gridAPI . get_cell_by_index ( 3 , 'HireDate' ) ;
230
258
const secondCell = grid . gridAPI . get_cell_by_index ( 1 , 'ID' ) ;
@@ -341,7 +369,7 @@ describe('IgxGrid - Cell selection #grid', () => {
341
369
] ;
342
370
const expectedData2 = [
343
371
{ ID : 475 , ParentID : 147 , Name : 'Michael Langdon' } ,
344
- { ID : 957 , ParentID : 147 } ,
372
+ { ID : 957 } ,
345
373
{ ID : 317 , ParentID : 147 }
346
374
] ;
347
375
@@ -362,18 +390,17 @@ describe('IgxGrid - Cell selection #grid', () => {
362
390
GridSelectionFunctions . verifyCellsRegionSelected ( grid , 0 , 2 , 0 , 1 ) ;
363
391
GridSelectionFunctions . verifyCellSelected ( thirdCell ) ;
364
392
365
- // Click on a cell in the region and verify it is not changed
393
+ // Click on a cell in the region and verify it is deselected
366
394
let cell = grid . gridAPI . get_cell_by_index ( 1 , 'ParentID' ) ;
367
395
UIInteractions . simulateClickAndSelectEvent ( cell , false , true ) ;
368
396
fix . detectChanges ( ) ;
369
397
370
- GridSelectionFunctions . verifyCellsRegionSelected ( grid , 0 , 2 , 0 , 1 ) ;
371
- GridSelectionFunctions . verifyCellSelected ( thirdCell ) ;
398
+ GridSelectionFunctions . verifyCellsRegionSelected ( grid , 0 , 0 , 0 , 2 ) ;
399
+ GridSelectionFunctions . verifyCellsRegionSelected ( grid , 2 , 2 , 0 , 1 ) ;
400
+ GridSelectionFunctions . verifyCellSelected ( cell , false ) ;
401
+ GridSelectionFunctions . verifyCellSelected ( grid . gridAPI . get_cell_by_index ( 1 , 'ID' ) , true ) ;
372
402
expect ( selectionChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
373
403
expect ( grid . getSelectedData ( ) ) . toEqual ( expectedData2 ) ;
374
- GridSelectionFunctions . verifySelectedRange ( grid , 0 , 2 , 0 , 1 , 0 , 3 ) ;
375
- GridSelectionFunctions . verifySelectedRange ( grid , 0 , 0 , 2 , 2 , 1 , 3 ) ;
376
- GridSelectionFunctions . verifySelectedRange ( grid , 1 , 1 , 1 , 1 , 2 , 3 ) ;
377
404
378
405
// Click on a cell without holding Ctrl
379
406
cell = grid . gridAPI . get_cell_by_index ( 0 , 'ID' ) ;
@@ -3155,6 +3182,25 @@ describe('IgxGrid - Cell selection #grid', () => {
3155
3182
GridSelectionFunctions . verifySelectedRange ( grid , 0 , 0 , 0 , 0 ) ;
3156
3183
} ) ;
3157
3184
3185
+ it ( 'Should deselect a selected cell with Ctrl + click' , ( ) => {
3186
+ const selectionChangeSpy = spyOn < any > ( grid . selected , 'emit' ) . and . callThrough ( ) ;
3187
+ const firstCell = grid . gridAPI . get_cell_by_index ( 1 , 'ParentID' ) ;
3188
+
3189
+ // Click on a cell
3190
+ UIInteractions . simulateClickAndSelectEvent ( firstCell ) ;
3191
+ fix . detectChanges ( ) ;
3192
+ GridSelectionFunctions . verifyCellSelected ( firstCell ) ;
3193
+ expect ( grid . selectedCells . length ) . toBe ( 1 ) ;
3194
+ expect ( selectionChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
3195
+
3196
+ // Click on same cell holding Ctrl
3197
+ UIInteractions . simulateClickAndSelectEvent ( firstCell , false , true ) ;
3198
+ fix . detectChanges ( ) ;
3199
+ GridSelectionFunctions . verifyCellSelected ( firstCell , false ) ;
3200
+ expect ( grid . selectedCells . length ) . toBe ( 0 ) ;
3201
+ expect ( selectionChangeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
3202
+ } ) ;
3203
+
3158
3204
it ( 'When when navigate with arrow keys cell selection should be changed' , ( ) => {
3159
3205
const selectionChangeSpy = spyOn < any > ( grid . selected , 'emit' ) . and . callThrough ( ) ;
3160
3206
let cell = grid . gridAPI . get_cell_by_index ( 1 , 'Name' ) ;
0 commit comments