Skip to content

bug(MatDialog): mat-dialog-title does not reset the `aria-labelledby #27599

@kaitibritt

Description

@kaitibritt

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Imagine you want to change the title of the dialog dynamically by having multiple headers and choosing the current one by *ngIf:

<div class="dialog">
   <div *ngIf="creating" mat-dialog-title class="header">Create User</div>
   <div *ngIf="!creating" mat-dialog-title class="header">Edit User</div>
   ....
</div>

Unfortunately, this won't work with the current mat-dialog-title directive implementation, cause it has an extra check:

if (container && !container._ariaLabelledBy) {
   container._ariaLabelledBy = this.id;
}

In other words, when the first mat-dialog-title directive (for the "Create User" case) is applied, it set the container._ariaLabelledBy for the first and last time. All future requests to amend the container._ariaLabelledBy won't go through, as the value is already present.

With current behaviour the only way to provide the accessible description to the dialog is by setting ariaLabel within the dialog configuration that is not flexible enough.

Reproduction

I was told that I can skip this step as the developer knows the context.

Expected Behavior

The aria-labelledby attributes is updated when a new mat-dialog-title is dynamically applied on the dialog.

Actual Behavior

The aria-labelledby attributes is not updated, keeping the previous title element id that breaks the accessibility and causes the aria-dialog-name violation.

Environment

Angular: 16.2.0-next.2
Globally, the current wrong behaviour does not depend on the environment.

Metadata

Metadata

Assignees

Labels

AccessibilityThis issue is related to accessibility (a11y)GThis is is related to a Google internal issueP3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/dialog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions