fix(commons/text): exclude natively hidden elements from aria-labelledby accessible name#5076
Open
nami8824 wants to merge 2 commits intodequelabs:developfrom
Open
Conversation
…dby accessible name style, script, noscript, and template elements are natively hidden and should not contribute to the accessible name even when referenced via aria-labelledby with includeHidden context. Closes issue dequelabs#4704
WilcoFiers
requested changes
Apr 16, 2026
Contributor
WilcoFiers
left a comment
There was a problem hiding this comment.
Looks solid. I'd like to see one test case added.
| assert.equal(axe.commons.text.accessibleTextVirtual(target), '', tag); | ||
| }); | ||
| }); | ||
|
|
Contributor
There was a problem hiding this comment.
I think this is worth having a test for too. This isn't about hiding content. The element itself should be ignored. There are elements with hidden content that aren't themselves hidden (canvas, iframe). The fix here is specifically about hiding the element.
Suggested change
| it('should ignore aria-label as accessible name when directly referenced by aria-labelledby', () => { | |
| tags.forEach(tag => { | |
| fixture.innerHTML = `<div id="t1" aria-labelledby="el-id"></div><${tag} id="el-id" aria-label="aria-label"></${tag}>`; | |
| axe.testUtils.flatTreeSetup(fixture); | |
| const target = axe.utils.querySelectorAll(axe._tree, '#t1')[0]; | |
| assert.equal(axe.commons.text.accessibleTextVirtual(target), '', tag); | |
| }); | |
| }); | |
Contributor
Author
There was a problem hiding this comment.
Added the test case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes accessible name calculation to correctly exclude
<style>contents, as well as<script>,<noscript>, and<template>, when referenced viaaria-labelledby.Closes #4704