Steps to Reproduce
- Run a Listbox with A11y module
- Click any Listitem
Current Result
Console log with an error:
Blocked aria-hidden on a <div> element because the element that just received 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.
<div id="n7JG1-a" style="top: 256px; left: 0px;" class="z-focus-a" tabindex="-1" aria-labelledby="n7JG1" aria-label="focus" aria-hidden="true"></div>
Expected Result
No error or warning on the console log.
Debug Information
The aria-hidden="true" attribute is set with focusable element will cause Chrome to show warning in the console. Such as a Div element with tabindex="" or Input element.
Workaround
add the following script to prevent this warning.
document.body.addEventListener('focusin', function(event) { // Checking if the target element is focusable and has `aria-hidden` var parent = event.target; while (parent && parent != document.body) { if (parent.getAttribute('aria-hidden') === "true") { parent.setAttribute('aria-hidden', 'false'); } parent = parent.parentNode; } }); document.body.addEventListener('focusout', function(event) { // Resetting aria-hidden to true when element loses focus var parent = event.target; while (parent && parent != document.body) { if (parent.getAttribute('aria-hidden') === "false") { parent.setAttribute('aria-hidden', 'true'); } parent = parent.parentNode; } });