-
Notifications
You must be signed in to change notification settings - Fork 6.8k
bug(COMPONENT): Blocked aria-hidden on an element because its descendant retained focus. #30187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm experiencing the same issue when using MatDialog in Angular Material version 16.2.14. The error I see in the browser console is: "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." This happens when I open a dialog, and it seems related to how aria-hidden is applied to the background content while the dialog is active. From what I've researched, this issue appears to have been present since version 13 of Angular Material and still persists in the current version. |
I was able to resolve this issue using the solution provided in this StackOverflow thread. Before opening the dialog, I added the following lines of code to ensure that the previously focused element (e.g., a button) loses focus: This prevents the error by ensuring that no focused element is hidden by the aria-hidden attribute when the dialog is opened. It worked perfectly for me! Let me know if it helps you too. |
+1 |
@ymdelgado2332 wouldn't that fix the error but still break accessibility? The focus should be returned to the original element once the dialog is closed, otherwise a mouse-less user might have to tab down all the way from the top. I'm trying to play around with the |
We have a similar issue. fixed it by adding
|
nice solution! thanks! |
had the same issue with vueJs3 and primevue. |
This issue is related to accessibility. To resolve this, you can use the inert attribute instead of aria-hidden, which will also prevent focus. inert should be true with dialog is show otherwise false. |
seems like the most "correct" way to do it. not working for me though... tried a few different variations of the config. but nothing. |
Yes this seems like the solution - hopefully the Angular Material team will look into it |
{ |
Thank you for link! I used @asgarov1's solution with a custom directive. |
The dialog moves focus in an `afterRender`, because it needs to give the content some time to be rendered. This is problematic with some relatively recent behavior in Chrome where the `aria-hidden` gets blocked and a warning is logged if it contains the focused element. These changes add a way for the container to indicate when it's done moving focus and use the new API to apply the `aria-hidden`. Fixes angular#30187.
The dialog moves focus in an `afterRender`, because it needs to give the content some time to be rendered. This is problematic with some relatively recent behavior in Chrome where the `aria-hidden` gets blocked and a warning is logged if it contains the focused element. These changes add a way for the container to indicate when it's done moving focus and use the new API to apply the `aria-hidden`. Fixes angular#30187.
The dialog moves focus in an `afterRender`, because it needs to give the content some time to be rendered. This is problematic with some relatively recent behavior in Chrome where the `aria-hidden` gets blocked and a warning is logged if it contains the focused element. These changes add a way for the container to indicate when it's done moving focus and use the new API to apply the `aria-hidden`. Fixes angular#30187.
…gular#31030) The dialog moves focus in an `afterRender`, because it needs to give the content some time to be rendered. This is problematic with some relatively recent behavior in Chrome where the `aria-hidden` gets blocked and a warning is logged if it contains the focused element. These changes add a way for the container to indicate when it's done moving focus and use the new API to apply the `aria-hidden`. Fixes angular#30187.
…1030) (#31036) The dialog moves focus in an `afterRender`, because it needs to give the content some time to be rendered. This is problematic with some relatively recent behavior in Chrome where the `aria-hidden` gets blocked and a warning is logged if it contains the focused element. These changes add a way for the container to indicate when it's done moving focus and use the new API to apply the `aria-hidden`. Fixes #30187.
…gular#31030) The dialog moves focus in an `afterRender`, because it needs to give the content some time to be rendered. This is problematic with some relatively recent behavior in Chrome where the `aria-hidden` gets blocked and a warning is logged if it contains the focused element. These changes add a way for the container to indicate when it's done moving focus and use the new API to apply the `aria-hidden`. Fixes angular#30187.
Is this a regression?
The previous version in which this bug was not present was
No response
Description
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: button
Ancestor with aria-hidden: <material-docs-app ng-version="19.0.4" aria-hidden="true">…flex...
also visible when trying the examples in chrome (Version 131.0.6778.109 (Official Build) (arm64))
https://material.angular.io/components/dialog/overview
happens when the dialog has a button...
Reproduction
examples on the material.angular.io:
https://material.angular.io/components/dialog/overview
Expected Behavior
no error
Actual Behavior
works, but shows an error in the console
Environment
The text was updated successfully, but these errors were encountered: