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 ,
@@ -505,6 +506,33 @@ describe('MatSelectionList without forms', () => {
505506 expect ( selectionList . nativeElement . getAttribute ( 'aria-multiselectable' ) ) . toBe ( 'true' ) ;
506507 } ) ;
507508
509+ it ( 'should disable list item ripples when the ripples on the list have been disabled' ,
510+ fakeAsync ( ( ) => {
511+ const rippleTarget = fixture . nativeElement
512+ . querySelector ( '.mat-list-option:not(.mat-list-item-disabled) .mat-list-item-content' ) ;
513+ const { enterDuration, exitDuration} = defaultRippleAnimationConfig ;
514+
515+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
516+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
517+
518+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length )
519+ . toBe ( 1 , 'Expected ripples to be enabled by default.' ) ;
520+
521+ // Wait for the ripples to go away.
522+ tick ( enterDuration + exitDuration ) ;
523+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length )
524+ . toBe ( 0 , 'Expected ripples to go away.' ) ;
525+
526+ fixture . componentInstance . listRippleDisabled = true ;
527+ fixture . detectChanges ( ) ;
528+
529+ dispatchMouseEvent ( rippleTarget , 'mousedown' ) ;
530+ dispatchMouseEvent ( rippleTarget , 'mouseup' ) ;
531+
532+ expect ( rippleTarget . querySelectorAll ( '.mat-ripple-element' ) . length )
533+ . toBe ( 0 , 'Expected no ripples after list ripples are disabled.' ) ;
534+ } ) ) ;
535+
508536 } ) ;
509537
510538 describe ( 'with list option selected' , ( ) => {
@@ -1075,7 +1103,10 @@ describe('MatSelectionList with forms', () => {
10751103
10761104
10771105@Component ( { template : `
1078- <mat-selection-list id="selection-list-1" (selectionChange)="onValueChange($event)">
1106+ <mat-selection-list
1107+ id="selection-list-1"
1108+ (selectionChange)="onValueChange($event)"
1109+ [disableRipple]="listRippleDisabled">
10791110 <mat-list-option checkboxPosition="before" disabled="true" value="inbox">
10801111 Inbox (disabled selection-option)
10811112 </mat-list-option>
@@ -1092,6 +1123,7 @@ describe('MatSelectionList with forms', () => {
10921123 </mat-selection-list>` } )
10931124class SelectionListWithListOptions {
10941125 showLastOption : boolean = true ;
1126+ listRippleDisabled = false ;
10951127
10961128 onValueChange ( _change : MatSelectionListChange ) { }
10971129}
0 commit comments