@@ -494,6 +494,7 @@ describe('MatSelectionList without forms', () => {
494
494
} ) ;
495
495
496
496
it ( 'should select all items using ctrl + a' , ( ) => {
497
+ listOptions . forEach ( option => option . componentInstance . disabled = false ) ;
497
498
const event = createKeyboardEvent ( 'keydown' , A , selectionList . nativeElement ) ;
498
499
Object . defineProperty ( event , 'ctrlKey' , { get : ( ) => true } ) ;
499
500
@@ -505,6 +506,23 @@ describe('MatSelectionList without forms', () => {
505
506
expect ( listOptions . every ( option => option . componentInstance . selected ) ) . toBe ( true ) ;
506
507
} ) ;
507
508
509
+ it ( 'should not select disabled items when pressing ctrl + a' , ( ) => {
510
+ const event = createKeyboardEvent ( 'keydown' , A , selectionList . nativeElement ) ;
511
+ Object . defineProperty ( event , 'ctrlKey' , { get : ( ) => true } ) ;
512
+
513
+ listOptions . slice ( 0 , 2 ) . forEach ( option => option . componentInstance . disabled = true ) ;
514
+ fixture . detectChanges ( ) ;
515
+
516
+ expect ( listOptions . map ( option => option . componentInstance . selected ) )
517
+ . toEqual ( [ false , false , false , false , false ] ) ;
518
+
519
+ dispatchEvent ( selectionList . nativeElement , event ) ;
520
+ fixture . detectChanges ( ) ;
521
+
522
+ expect ( listOptions . map ( option => option . componentInstance . selected ) )
523
+ . toEqual ( [ false , false , true , true , true ] ) ;
524
+ } ) ;
525
+
508
526
it ( 'should select all items using ctrl + a if some items are selected' , ( ) => {
509
527
const event = createKeyboardEvent ( 'keydown' , A , selectionList . nativeElement ) ;
510
528
Object . defineProperty ( event , 'ctrlKey' , { get : ( ) => true } ) ;
@@ -617,6 +635,20 @@ describe('MatSelectionList without forms', () => {
617
635
expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( true ) ;
618
636
} ) ;
619
637
638
+ it ( 'should be able to select all options, even if they are disabled' , ( ) => {
639
+ const list : MatSelectionList = selectionList . componentInstance ;
640
+
641
+ list . options . forEach ( option => option . disabled = true ) ;
642
+ fixture . detectChanges ( ) ;
643
+
644
+ expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( false ) ;
645
+
646
+ list . selectAll ( ) ;
647
+ fixture . detectChanges ( ) ;
648
+
649
+ expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( true ) ;
650
+ } ) ;
651
+
620
652
it ( 'should be able to deselect all options' , ( ) => {
621
653
const list : MatSelectionList = selectionList . componentInstance ;
622
654
@@ -629,6 +661,21 @@ describe('MatSelectionList without forms', () => {
629
661
expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( false ) ;
630
662
} ) ;
631
663
664
+ it ( 'should be able to deselect all options, even if they are disabled' , ( ) => {
665
+ const list : MatSelectionList = selectionList . componentInstance ;
666
+
667
+ list . options . forEach ( option => option . toggle ( ) ) ;
668
+ expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( true ) ;
669
+
670
+ list . options . forEach ( option => option . disabled = true ) ;
671
+ fixture . detectChanges ( ) ;
672
+
673
+ list . deselectAll ( ) ;
674
+ fixture . detectChanges ( ) ;
675
+
676
+ expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( false ) ;
677
+ } ) ;
678
+
632
679
it ( 'should update the list value when an item is selected programmatically' , ( ) => {
633
680
const list : MatSelectionList = selectionList . componentInstance ;
634
681
0 commit comments