4
4
dispatchFakeEvent ,
5
5
dispatchEvent ,
6
6
dispatchKeyboardEvent ,
7
+ dispatchMouseEvent ,
7
8
} from '@angular/cdk/testing' ;
8
9
import {
9
10
Component ,
@@ -13,7 +14,7 @@ import {
13
14
ViewChildren ,
14
15
} from '@angular/core' ;
15
16
import { async , ComponentFixture , fakeAsync , TestBed , tick , flush } from '@angular/core/testing' ;
16
- import { MatRipple } from '@angular/material/core' ;
17
+ import { MatRipple , defaultRippleAnimationConfig } from '@angular/material/core' ;
17
18
import { By } from '@angular/platform-browser' ;
18
19
import {
19
20
MatListModule ,
@@ -521,6 +522,33 @@ describe('MatSelectionList without forms', () => {
521
522
expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( true ) ;
522
523
} ) ;
523
524
525
+ it ( 'should disable list item ripples when the ripples on the list have been disabled' ,
526
+ fakeAsync ( ( ) => {
527
+ const rippleTarget = fixture . nativeElement
528
+ . querySelector ( '.mat-list-option:not(.mat-list-item-disabled) .mat-list-item-content' ) ;
529
+ const { enterDuration, exitDuration} = defaultRippleAnimationConfig ;
530
+
531
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
532
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
533
+
534
+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length )
535
+ . toBe ( 1 , 'Expected ripples to be enabled by default.' ) ;
536
+
537
+ // Wait for the ripples to go away.
538
+ tick ( enterDuration + exitDuration ) ;
539
+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length )
540
+ . toBe ( 0 , 'Expected ripples to go away.' ) ;
541
+
542
+ fixture . componentInstance . listRippleDisabled = true ;
543
+ fixture . detectChanges ( ) ;
544
+
545
+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
546
+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
547
+
548
+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length )
549
+ . toBe ( 0 , 'Expected no ripples after list ripples are disabled.' ) ;
550
+ } ) ) ;
551
+
524
552
} ) ;
525
553
526
554
describe ( 'with list option selected' , ( ) => {
@@ -1091,7 +1119,10 @@ describe('MatSelectionList with forms', () => {
1091
1119
1092
1120
1093
1121
@Component ( { template : `
1094
- <mat-selection-list id="selection-list-1" (selectionChange)="onValueChange($event)">
1122
+ <mat-selection-list
1123
+ id="selection-list-1"
1124
+ (selectionChange)="onValueChange($event)"
1125
+ [disableRipple]="listRippleDisabled">
1095
1126
<mat-list-option checkboxPosition="before" disabled="true" value="inbox">
1096
1127
Inbox (disabled selection-option)
1097
1128
</mat-list-option>
@@ -1108,6 +1139,7 @@ describe('MatSelectionList with forms', () => {
1108
1139
</mat-selection-list>` } )
1109
1140
class SelectionListWithListOptions {
1110
1141
showLastOption : boolean = true ;
1142
+ listRippleDisabled = false ;
1111
1143
1112
1144
onValueChange ( _change : MatSelectionListChange ) { }
1113
1145
}
0 commit comments