@@ -1587,12 +1587,14 @@ describe('MDC-based MatDialog', () => {
15871587
15881588 describe ( 'dialog content elements' , ( ) => {
15891589 let dialogRef : MatDialogRef < any > ;
1590+ let hostInstance : ContentElementDialog | ComponentWithContentElementTemplateRef ;
15901591
15911592 describe ( 'inside component dialog' , ( ) => {
15921593 beforeEach ( fakeAsync ( ( ) => {
15931594 dialogRef = dialog . open ( ContentElementDialog , { viewContainerRef : testViewContainerRef } ) ;
15941595 viewContainerFixture . detectChanges ( ) ;
15951596 flush ( ) ;
1597+ hostInstance = dialogRef . componentInstance ;
15961598 } ) ) ;
15971599
15981600 runContentElementTests ( ) ;
@@ -1609,6 +1611,7 @@ describe('MDC-based MatDialog', () => {
16091611
16101612 viewContainerFixture . detectChanges ( ) ;
16111613 flush ( ) ;
1614+ hostInstance = fixture . componentInstance ;
16121615 } ) ) ;
16131616
16141617 runContentElementTests ( ) ;
@@ -1682,6 +1685,49 @@ describe('MDC-based MatDialog', () => {
16821685 . toBe ( title . id ) ;
16831686 } ) ) ;
16841687
1688+ it ( 'should update the aria-labelledby attribute if two titles are swapped' , fakeAsync ( ( ) => {
1689+ const container = overlayContainerElement . querySelector ( 'mat-dialog-container' ) ! ;
1690+ let title = overlayContainerElement . querySelector ( '[mat-dialog-title]' ) ! ;
1691+
1692+ flush ( ) ;
1693+ viewContainerFixture . detectChanges ( ) ;
1694+
1695+ const previousId = title . id ;
1696+ expect ( title . id ) . toBeTruthy ( ) ;
1697+ expect ( container . getAttribute ( 'aria-labelledby' ) ) . toBe ( title . id ) ;
1698+
1699+ hostInstance . shownTitle = 'second' ;
1700+ viewContainerFixture . detectChanges ( ) ;
1701+ flush ( ) ;
1702+ viewContainerFixture . detectChanges ( ) ;
1703+ title = overlayContainerElement . querySelector ( '[mat-dialog-title]' ) ! ;
1704+
1705+ expect ( title . id ) . toBeTruthy ( ) ;
1706+ expect ( title . id ) . not . toBe ( previousId ) ;
1707+ expect ( container . getAttribute ( 'aria-labelledby' ) ) . toBe ( title . id ) ;
1708+ } ) ) ;
1709+
1710+ it ( 'should update the aria-labelledby attribute if multiple titles are present and one is removed' , fakeAsync ( ( ) => {
1711+ const container = overlayContainerElement . querySelector ( 'mat-dialog-container' ) ! ;
1712+
1713+ hostInstance . shownTitle = 'all' ;
1714+ viewContainerFixture . detectChanges ( ) ;
1715+ flush ( ) ;
1716+ viewContainerFixture . detectChanges ( ) ;
1717+
1718+ const titles = overlayContainerElement . querySelectorAll ( '[mat-dialog-title]' ) ;
1719+
1720+ expect ( titles . length ) . toBe ( 3 ) ;
1721+ expect ( container . getAttribute ( 'aria-labelledby' ) ) . toBe ( titles [ 0 ] . id ) ;
1722+
1723+ hostInstance . shownTitle = 'second' ;
1724+ viewContainerFixture . detectChanges ( ) ;
1725+ flush ( ) ;
1726+ viewContainerFixture . detectChanges ( ) ;
1727+
1728+ expect ( container . getAttribute ( 'aria-labelledby' ) ) . toBe ( titles [ 1 ] . id ) ;
1729+ } ) ) ;
1730+
16851731 it ( 'should add correct css class according to given [align] input in [mat-dialog-actions]' , ( ) => {
16861732 let actions = overlayContainerElement . querySelector ( 'mat-dialog-actions' ) ! ;
16871733
@@ -2116,7 +2162,9 @@ class PizzaMsg {
21162162
21172163@Component ( {
21182164 template : `
2119- <h1 mat-dialog-title>This is the title</h1>
2165+ <h1 mat-dialog-title *ngIf="shouldShowTitle('first')">This is the first title</h1>
2166+ <h1 mat-dialog-title *ngIf="shouldShowTitle('second')">This is the second title</h1>
2167+ <h1 mat-dialog-title *ngIf="shouldShowTitle('third')">This is the third title</h1>
21202168 <mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
21212169 <mat-dialog-actions align="end">
21222170 <button mat-dialog-close>Close</button>
@@ -2130,12 +2178,20 @@ class PizzaMsg {
21302178 </mat-dialog-actions>
21312179 ` ,
21322180} )
2133- class ContentElementDialog { }
2181+ class ContentElementDialog {
2182+ shownTitle : 'first' | 'second' | 'third' | 'all' = 'first' ;
2183+
2184+ shouldShowTitle ( name : string ) {
2185+ return this . shownTitle === 'all' || this . shownTitle === name ;
2186+ }
2187+ }
21342188
21352189@Component ( {
21362190 template : `
21372191 <ng-template>
2138- <h1 mat-dialog-title>This is the title</h1>
2192+ <h1 mat-dialog-title *ngIf="shouldShowTitle('first')">This is the first title</h1>
2193+ <h1 mat-dialog-title *ngIf="shouldShowTitle('second')">This is the second title</h1>
2194+ <h1 mat-dialog-title *ngIf="shouldShowTitle('third')">This is the third title</h1>
21392195 <mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
21402196 <mat-dialog-actions align="end">
21412197 <button mat-dialog-close>Close</button>
@@ -2152,6 +2208,12 @@ class ContentElementDialog {}
21522208} )
21532209class ComponentWithContentElementTemplateRef {
21542210 @ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
2211+
2212+ shownTitle : 'first' | 'second' | 'third' | 'all' = 'first' ;
2213+
2214+ shouldShowTitle ( name : string ) {
2215+ return this . shownTitle === 'all' || this . shownTitle === name ;
2216+ }
21552217}
21562218
21572219@Component ( { template : '' , providers : [ MatDialog ] } )
0 commit comments