44 dispatchFakeEvent ,
55 dispatchEvent ,
66 dispatchKeyboardEvent ,
7+ dispatchMouseEvent ,
78} from '@angular/cdk/testing' ;
89import {
910 Component ,
@@ -13,7 +14,7 @@ import {
1314 ViewChildren ,
1415} from '@angular/core' ;
1516import { 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' ;
1718import { By } from '@angular/platform-browser' ;
1819import {
1920 MatListModule ,
@@ -521,6 +522,33 @@ describe('MatSelectionList without forms', () => {
521522 expect ( list . options . toArray ( ) . every ( option => option . selected ) ) . toBe ( true ) ;
522523 } ) ;
523524
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+
524552 } ) ;
525553
526554 describe ( 'with list option selected' , ( ) => {
@@ -1091,7 +1119,10 @@ describe('MatSelectionList with forms', () => {
10911119
10921120
10931121@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">
10951126 <mat-list-option checkboxPosition="before" disabled="true" value="inbox">
10961127 Inbox (disabled selection-option)
10971128 </mat-list-option>
@@ -1108,6 +1139,7 @@ describe('MatSelectionList with forms', () => {
11081139 </mat-selection-list>` } )
11091140class SelectionListWithListOptions {
11101141 showLastOption : boolean = true ;
1142+ listRippleDisabled = false ;
11111143
11121144 onValueChange ( _change : MatSelectionListChange ) { }
11131145}
0 commit comments