11import { fakeAsync , TestBed , waitForAsync } from '@angular/core/testing' ;
22import { dispatchFakeEvent , dispatchMouseEvent } from '@angular/cdk/testing/private' ;
3- import { Component , QueryList , ViewChildren } from '@angular/core' ;
3+ import { Component , QueryList , ViewChild , ViewChildren } from '@angular/core' ;
44import { By } from '@angular/platform-browser' ;
55import { MatListItem , MatListModule } from './index' ;
66
@@ -22,6 +22,8 @@ describe('MDC-based MatList', () => {
2222 NavListWithActivatedItem ,
2323 ActionListWithoutType ,
2424 ActionListWithType ,
25+ ActionListWithDisabledList ,
26+ ActionListWithDisabledItem ,
2527 ListWithDisabledItems ,
2628 StandaloneListItem ,
2729 ] ,
@@ -377,6 +379,34 @@ describe('MDC-based MatList', () => {
377379 fixture . detectChanges ( ) ;
378380 } ) . not . toThrow ( ) ;
379381 } ) ;
382+
383+ it ( 'should be able to disable and enable the entire action list' , ( ) => {
384+ const fixture = TestBed . createComponent ( ActionListWithDisabledList ) ;
385+ const listItems : HTMLElement [ ] = Array . from (
386+ fixture . nativeElement . querySelectorAll ( '[mat-list-item]' ) ,
387+ ) ;
388+ fixture . detectChanges ( ) ;
389+
390+ expect ( listItems . every ( listItem => listItem . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
391+
392+ fixture . componentInstance . disableList = false ;
393+ fixture . detectChanges ( ) ;
394+
395+ expect ( listItems . every ( listItem => ! listItem . hasAttribute ( 'disabled' ) ) ) . toBe ( true ) ;
396+ } ) ;
397+
398+ it ( 'should be able to disable and enable button item' , ( ) => {
399+ const fixture = TestBed . createComponent ( ActionListWithDisabledItem ) ;
400+ const buttonItem : HTMLButtonElement = fixture . nativeElement . querySelector ( '[mat-list-item]' ) ;
401+ fixture . detectChanges ( ) ;
402+
403+ expect ( buttonItem . hasAttribute ( 'disabled' ) ) . toBe ( true ) ;
404+
405+ fixture . componentInstance . buttonItem . disabled = false ;
406+ fixture . detectChanges ( ) ;
407+
408+ expect ( buttonItem . hasAttribute ( 'disabled' ) ) . toBe ( false ) ;
409+ } ) ;
380410} ) ;
381411
382412class BaseTestList {
@@ -460,6 +490,31 @@ class ActionListWithType extends BaseTestList {
460490 @ViewChildren ( MatListItem ) listItems : QueryList < MatListItem > ;
461491}
462492
493+ @Component ( {
494+ template : `
495+ <mat-action-list [disabled]="disableList">
496+ <button mat-list-item *ngFor="let item of items">
497+ {{item.name}}
498+ </button>
499+ </mat-action-list>` ,
500+ } )
501+ class ActionListWithDisabledList extends BaseTestList {
502+ disableList = true ;
503+ }
504+
505+ @Component ( {
506+ template : `
507+ <mat-action-list>
508+ <button mat-list-item [disabled]="disableItem">
509+ Paprika
510+ </button>
511+ </mat-action-list>` ,
512+ } )
513+ class ActionListWithDisabledItem extends BaseTestList {
514+ @ViewChild ( MatListItem ) buttonItem : MatListItem ;
515+ disableItem = true ;
516+ }
517+
463518@Component ( {
464519 template : `
465520 <mat-list>
0 commit comments