@@ -10,6 +10,7 @@ import {FocusMonitor, FocusTrapFactory, InteractivityChecker} from '@angular/cdk
10
10
import { OverlayRef } from '@angular/cdk/overlay' ;
11
11
import { DOCUMENT } from '@angular/common' ;
12
12
import {
13
+ AfterViewInit ,
13
14
ChangeDetectionStrategy ,
14
15
Component ,
15
16
ComponentRef ,
@@ -25,7 +26,9 @@ import {
25
26
import { MatDialogConfig } from './dialog-config' ;
26
27
import { CdkDialogContainer } from '@angular/cdk/dialog' ;
27
28
import { coerceNumberProperty } from '@angular/cdk/coercion' ;
29
+ import { PlatformModule } from '@angular/cdk/platform' ;
28
30
import { CdkPortalOutlet , ComponentPortal } from '@angular/cdk/portal' ;
31
+ import { Observable , Subject , Subscription , defer , fromEvent , merge , of as observableOf } from 'rxjs' ;
29
32
30
33
/** Event that captures the state of dialog container animations. */
31
34
interface LegacyDialogAnimationEvent {
@@ -71,7 +74,10 @@ export const CLOSE_ANIMATION_DURATION = 75;
71
74
'[class.mat-mdc-dialog-container-with-actions]' : '_actionSectionCount > 0' ,
72
75
} ,
73
76
} )
74
- export class MatDialogContainer extends CdkDialogContainer < MatDialogConfig > implements OnDestroy {
77
+ export class MatDialogContainer
78
+ extends CdkDialogContainer < MatDialogConfig >
79
+ implements AfterViewInit , OnDestroy
80
+ {
75
81
/** Emits when an animation state changes. */
76
82
_animationStateChanged = new EventEmitter < LegacyDialogAnimationEvent > ( ) ;
77
83
@@ -93,6 +99,11 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
93
99
: 0 ;
94
100
/** Current timer for dialog animations. */
95
101
private _animationTimer : ReturnType < typeof setTimeout > | null = null ;
102
+ /** Platform Observer */
103
+ // private _userAgentSubscription = Subscription.EMPTY;
104
+ private _getWindow ( ) : Window {
105
+ return this . _document ?. defaultView || window ;
106
+ }
96
107
97
108
constructor (
98
109
elementRef : ElementRef ,
@@ -117,6 +128,30 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
117
128
) ;
118
129
}
119
130
131
+ /** Get Dialog name from aria attributes */
132
+ private _getDialogName = async ( ) : Promise < void > => {
133
+ const configData = this . _config ;
134
+ /**_ariaLabelledByQueue and _ariaDescribedByQueue are created if ariaLabelledBy
135
+ or ariaDescribedBy values are applied to the dialog config
136
+ */
137
+ const ariaLabelledByRefId = await this . _ariaLabelledByQueue [ 0 ] ;
138
+ const ariaDescribedByRefId = await this . _ariaDescribedByQueue [ 0 ] ;
139
+ /** Get Element to get name/title from if ariaLabelledBy or ariaDescribedBy */
140
+ const dialogNameElement =
141
+ document . getElementById ( ariaLabelledByRefId ) || document . getElementById ( ariaDescribedByRefId ) ;
142
+ const dialogNameInnerText =
143
+ /** If no ariaLabelledBy, ariaDescribedBy, or ariaLabel, create default aria label */
144
+ ! dialogNameElement || ! this . _config . ariaLabel
145
+ ? 'Dialog Modal'
146
+ : /** Otherwise prioritize use of ariaLabel */
147
+ this . _config . ariaLabel || dialogNameElement ?. innerText || dialogNameElement ?. ariaLabel ;
148
+ return ;
149
+ } ;
150
+ ngAfterViewInit ( ) {
151
+ const window = this . _getWindow ( ) ;
152
+ this . _getDialogName ( ) ;
153
+ }
154
+
120
155
protected override _contentAttached ( ) : void {
121
156
// Delegate to the original dialog-container initialization (i.e. saving the
122
157
// previous element, setting up the focus trap and moving focus to the container).
0 commit comments