angular / angular/components

bug(MatDialog): Blocked aria-hidden on an element because its descendant retained focus

Open
#31,927 4 comments 0 reactions 0 assignees View on GitHub
Accessibility area: material/dialog P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### Is this a regression?

- [x] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

Angular: 18.2

### Description

This is a follow up of https://github.com/angular/components/issues/30187

That fix works, but not for dialogs in a tree view

const ok = await firstValueFrom(
this.matDialog.open(AddNodeDialogComponent, { data, maxHeight: '90vh', width: '650px', autoFocus: 'first-heading', restoreFocus: true }).afterClosed(),
);

Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at https://w3c.github.io/aria/#aria-hidden.
Element with focus:
Ancestor with aria-hidden: ​…​​

### Reproduction

StackBlitz link:
Steps to reproduce:
1. https://stackblitz.com/edit/rwbw9hex?file=src%2Fexample%2Ftree-dynamic-example.ts
2. Click on the + icon to open a dialog. The focus stays on the background

### Expected Behavior

Add focus to the dialog and don't show warning message

### Actual Behavior

Unable to set focus to dialog

### Environment

@angular-devkit/architect 0.2001.6
@angular-devkit/core 20.2.2
@angular-devkit/schematics 20.2.2
@schematics/angular 20.1.6

Chrome 140 Windows

Contributor guide

Open the contributing guide

Research direction

Start with the linked StackBlitz reproduction, especially src/example/tree-dynamic-example.ts, and trace the MatDialog focus behavior with the mat-tree trigger. Check how autoFocus and restoreFocus interact when the dialog opens. Done means focus moves into the dialog without the aria-hidden warning and the tree interaction remains working.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
accessibility, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.