@@ -331,10 +331,10 @@ describe('MatSelectionList without forms', () => {
331
331
dispatchEvent ( selectionList . nativeElement , event ) ;
332
332
fixture . detectChanges ( ) ;
333
333
334
- expect ( listOptions . every ( option => option . componentInstance . selected ) ) . toBe ( true ) ;
334
+ expect ( listOptions . filter ( option => option . componentInstance . selected ) . length ) . toBe ( 3 ) ;
335
335
} ) ;
336
336
337
- it ( 'should select all items using ctrl + a if some items are selected' , ( ) => {
337
+ it ( 'should select all items using ctrl + a if some options are selected' , ( ) => {
338
338
const event = createKeyboardEvent ( 'keydown' , A , selectionList . nativeElement ) ;
339
339
Object . defineProperty ( event , 'ctrlKey' , { get : ( ) => true } ) ;
340
340
@@ -364,6 +364,23 @@ describe('MatSelectionList without forms', () => {
364
364
expect ( listOptions . every ( option => option . componentInstance . selected ) ) . toBe ( false ) ;
365
365
} ) ;
366
366
367
+ it ( 'should select only non-disabled options when using ctrl + a' , ( ) => {
368
+ const event = createKeyboardEvent ( 'keydown' , A , selectionList . nativeElement ) ;
369
+ Object . defineProperty ( event , 'ctrlKey' , { get : ( ) => true } ) ;
370
+
371
+ const selectList =
372
+ selectionList . injector . get < MatSelectionList > ( MatSelectionList ) . selectedOptions ;
373
+
374
+ expect ( selectList . selected . length ) . toBe ( 0 ) ;
375
+ expect ( listOptions [ 0 ] . componentInstance . selected ) . toBe ( false ) ;
376
+
377
+ dispatchEvent ( selectionList . nativeElement , event ) ;
378
+ fixture . detectChanges ( ) ;
379
+
380
+ expect ( selectList . selected . length ) . toBe ( 3 ) ;
381
+ expect ( listOptions [ 0 ] . componentInstance . selected ) . toBe ( false ) ;
382
+ } ) ;
383
+
367
384
it ( 'should be able to jump focus down to an item by typing' , fakeAsync ( ( ) => {
368
385
const listEl = selectionList . nativeElement ;
369
386
const manager = selectionList . componentInstance . _keyManager ;
@@ -391,7 +408,7 @@ describe('MatSelectionList without forms', () => {
391
408
list . selectAll ( ) ;
392
409
fixture . detectChanges ( ) ;
393
410
394
- expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( true ) ;
411
+ expect ( list . options . toArray ( ) . filter ( option => option . selected ) . length ) . toBe ( 3 ) ;
395
412
} ) ;
396
413
397
414
it ( 'should be able to deselect all options' , ( ) => {
@@ -628,6 +645,21 @@ describe('MatSelectionList without forms', () => {
628
645
expect ( selectList . selected . length ) . toBe ( 0 ) ;
629
646
} ) ;
630
647
648
+ it ( 'should not allow select all using ctrl + a on disabled selection-list' , ( ) => {
649
+ const event = createKeyboardEvent ( 'keydown' , A , selectionList . nativeElement ) ;
650
+ Object . defineProperty ( event , 'ctrlKey' , { get : ( ) => true } ) ;
651
+
652
+ const selectList =
653
+ selectionList . injector . get < MatSelectionList > ( MatSelectionList ) . selectedOptions ;
654
+
655
+ expect ( selectList . selected . length ) . toBe ( 0 ) ;
656
+
657
+ dispatchEvent ( selectionList . nativeElement , event ) ;
658
+ fixture . detectChanges ( ) ;
659
+
660
+ expect ( selectList . selected . length ) . toBe ( 0 ) ;
661
+ } ) ;
662
+
631
663
it ( 'should update state of options if list state has changed' , ( ) => {
632
664
// To verify that the template of the list options has been re-rendered after the disabled
633
665
// property of the selection list has been updated, the ripple directive can be used.
0 commit comments