@@ -1587,12 +1587,14 @@ describe('MDC-based MatDialog', () => {
1587
1587
1588
1588
describe ( 'dialog content elements' , ( ) => {
1589
1589
let dialogRef : MatDialogRef < any > ;
1590
+ let hostInstance : ContentElementDialog | ComponentWithContentElementTemplateRef ;
1590
1591
1591
1592
describe ( 'inside component dialog' , ( ) => {
1592
1593
beforeEach ( fakeAsync ( ( ) => {
1593
1594
dialogRef = dialog . open ( ContentElementDialog , { viewContainerRef : testViewContainerRef } ) ;
1594
1595
viewContainerFixture . detectChanges ( ) ;
1595
1596
flush ( ) ;
1597
+ hostInstance = dialogRef . componentInstance ;
1596
1598
} ) ) ;
1597
1599
1598
1600
runContentElementTests ( ) ;
@@ -1609,6 +1611,7 @@ describe('MDC-based MatDialog', () => {
1609
1611
1610
1612
viewContainerFixture . detectChanges ( ) ;
1611
1613
flush ( ) ;
1614
+ hostInstance = fixture . componentInstance ;
1612
1615
} ) ) ;
1613
1616
1614
1617
runContentElementTests ( ) ;
@@ -1682,6 +1685,49 @@ describe('MDC-based MatDialog', () => {
1682
1685
. toBe ( title . id ) ;
1683
1686
} ) ) ;
1684
1687
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
+
1685
1731
it ( 'should add correct css class according to given [align] input in [mat-dialog-actions]' , ( ) => {
1686
1732
let actions = overlayContainerElement . querySelector ( 'mat-dialog-actions' ) ! ;
1687
1733
@@ -2116,7 +2162,9 @@ class PizzaMsg {
2116
2162
2117
2163
@Component ( {
2118
2164
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>
2120
2168
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
2121
2169
<mat-dialog-actions align="end">
2122
2170
<button mat-dialog-close>Close</button>
@@ -2130,12 +2178,20 @@ class PizzaMsg {
2130
2178
</mat-dialog-actions>
2131
2179
` ,
2132
2180
} )
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
+ }
2134
2188
2135
2189
@Component ( {
2136
2190
template : `
2137
2191
<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>
2139
2195
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
2140
2196
<mat-dialog-actions align="end">
2141
2197
<button mat-dialog-close>Close</button>
@@ -2152,6 +2208,12 @@ class ContentElementDialog {}
2152
2208
} )
2153
2209
class ComponentWithContentElementTemplateRef {
2154
2210
@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
+ }
2155
2217
}
2156
2218
2157
2219
@Component ( { template : '' , providers : [ MatDialog ] } )
0 commit comments