Skip to content

Commit db4c3c4

Browse files
committed
fix(material/dialog): dialog name not read on macOS chrome & firefox
Fixes Angular Components Dialog component where the dialog name is not read by VoiceOver/screenreader on macOS chrome & firefox browsers. Attempts to retrieve any id associated with aria-labelledby or aria-describedby and taking the innerHTML or the aria-label of that element and applying that value to the dialog's aria-label. Fixes b/274674581
1 parent 0dc67a3 commit db4c3c4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/material/dialog/dialog-container.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import {
2626
import {MatDialogConfig} from './dialog-config';
2727
import {CdkDialogContainer} from '@angular/cdk/dialog';
2828
import {coerceNumberProperty} from '@angular/cdk/coercion';
29-
import {PlatformModule} from '@angular/cdk/platform';
3029
import {CdkPortalOutlet, ComponentPortal} from '@angular/cdk/portal';
31-
import {Observable, Subject, Subscription, defer, fromEvent, merge, of as observableOf} from 'rxjs';
3230

3331
/** Event that captures the state of dialog container animations. */
3432
interface LegacyDialogAnimationEvent {
@@ -129,26 +127,27 @@ export class MatDialogContainer
129127
}
130128

131129
/** Get Dialog name from aria attributes */
132-
private _getDialogName = async (): Promise<void> => {
130+
private _getDialogName = async (): Promise<string> => {
133131
const configData = this._config;
134132
/**_ariaLabelledByQueue and _ariaDescribedByQueue are created if ariaLabelledBy
135-
or ariaDescribedBy values are applied to the dialog config
136-
*/
133+
or ariaDescribedBy values are applied to the dialog config */
137134
const ariaLabelledByRefId = await this._ariaLabelledByQueue[0];
138135
const ariaDescribedByRefId = await this._ariaDescribedByQueue[0];
139136
/** Get Element to get name/title from if ariaLabelledBy or ariaDescribedBy */
140137
const dialogNameElement =
141138
document.getElementById(ariaLabelledByRefId) || document.getElementById(ariaDescribedByRefId);
142139
const dialogNameInnerText =
143140
/** If no ariaLabelledBy, ariaDescribedBy, or ariaLabel, create default aria label */
144-
!dialogNameElement || !this._config.ariaLabel
141+
!dialogNameElement && !this._config.ariaLabel
145142
? 'Dialog Modal'
146143
: /** Otherwise prioritize use of ariaLabel */
147144
this._config.ariaLabel || dialogNameElement?.innerText || dialogNameElement?.ariaLabel;
148-
return;
145+
this._config.ariaLabel = dialogNameInnerText || 'Dialog Modal';
146+
console.log(`getDialogName this.config.ariaLabel: `);
147+
console.log(this._config.ariaLabel);
148+
return this._config.ariaLabel;
149149
};
150150
ngAfterViewInit() {
151-
const window = this._getWindow();
152151
this._getDialogName();
153152
}
154153

0 commit comments

Comments
 (0)