Skip to content

fix: honor ariaLabelledByElements in label resolution - #5187

Closed
jcfranco wants to merge 4 commits into
dequelabs:developfrom
jcfranco:4943-include-ariaLabelledByElements-in-label-resolution
Closed

fix: honor ariaLabelledByElements in label resolution#5187
jcfranco wants to merge 4 commits into
dequelabs:developfrom
jcfranco:4943-include-ariaLabelledByElements-in-label-resolution

Conversation

@jcfranco

Copy link
Copy Markdown
Contributor

Summary

This PR updates label resolution to include ariaLabelledByElements.

Disclaimer: I used Copilot to help drive this PR. The code looks good from what I can tell and tests are passing locally, but this is my first time contributing, so I could be missing something. Happy to make any requested changes!

Closes: #4943

@jcfranco
jcfranco requested a review from a team as a code owner June 25, 2026 07:51
Copilot AI review requested due to automatic review settings June 25, 2026 07:51
@CLAassistant

CLAassistant commented Jun 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates axe-core’s label/accessibility-name resolution to honor the ARIA AOM ariaLabelledByElements (and, more generally, prefer reflected idrefs properties via getResolvedRefs) so elements referenced through the AOM are used when computing labels.

Changes:

  • Switched aria-labelledby resolution in label/name helpers from attribute-only idrefs to dom.getResolvedRefs (which prefers AOM idrefs properties like ariaLabelledByElements).
  • Updated the multiple-label check evaluation to use resolved refs (including AOM overrides) when validating which label is referenced.
  • Added/extended unit tests across commons and checks to cover ariaLabelledByElements precedence scenarios.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/commons/aria/label-virtual.js Use getResolvedRefs for aria-labelledby so ariaLabelledByElements is honored.
lib/commons/aria/arialabelledby-text.js Resolve labelledby references via getResolvedRefs (supports AOM property even when attribute is unset).
lib/checks/label/multiple-label-evaluate.js Use getResolvedRefs when checking whether the AT-visible label is referenced.
test/commons/text/label-virtual.js Add tests ensuring ariaLabelledByElements overrides aria-labelledby/aria-label in label resolution.
test/commons/dom/get-resolved-refs.js Add test asserting idrefs property is preferred over attribute for aria-labelledby.
test/commons/aria/label-virtual.js Add tests ensuring ARIA label virtual prefers ariaLabelledByElements.
test/commons/aria/arialabelledby-text.js Add tests covering ariaLabelledByElements when attribute is unset and when both are present.
test/checks/label/multiple-label.js Add check-level tests for ariaLabelledByElements overriding attribute behaviour.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 36 to 42
if (
vNode.props.nodeType !== 1 ||
context.inLabelledByContext ||
context.inControlContext ||
!vNode.attr('aria-labelledby')
context.inControlContext
) {
return '';
}
@Garbee

Garbee commented Jun 25, 2026

Copy link
Copy Markdown
Member

Thanks for submitting a patch. Right now we have a lot of work going on for Element Internals support. So I think we first need to validate that this is not overlapping with any of that.

The person driving that effort is out this week, so he will check into this sometime next week to see what should be done.

@jcfranco

Copy link
Copy Markdown
Contributor Author

@Garbee Sounds good. Thanks for the heads-up!

@straker

straker commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for contributing to axe-core. I'm back from vacation and looking at the changes. As @Garbee said we've been working on element internals support, and looking over the changes they are currently being worked on in #5170 and #5171.

chutchins25 added a commit that referenced this pull request Jun 30, 2026
Add consumer-level tests for the reflected ariaLabelledByElements property
(precedence over aria-labelledby and aria-label) in arialabelledbyText and
labelVirtual. getResolvedRefs already honors the property; this regression-
tests the #4943 scenario. Tests adapted from #5187.

Co-authored-by: JC Franco <[email protected]>
chutchins25 added a commit that referenced this pull request Jun 30, 2026
Add coverage for the reflected ariaLabelledByElements property overriding
aria-labelledby in the multiple-label check. getResolvedRefs already honors
the property; this regression-tests the #4943 scenario. Tests adapted from
#5187.

Co-authored-by: JC Franco <[email protected]>
@chutchins25

Copy link
Copy Markdown
Contributor

Thanks for this, @jcfranco — nice instinct landing on the same idrefs → getResolvedRefs conversion we're already doing in #5170 (multiple-label) and #5171 (arialabelledby-text, label-virtual). getResolvedRefs reads ariaLabelledByElements first (it has to — setting that property empties the aria-labelledby attribute), so the production change is covered there.

Your consumer-level tests were exactly what those PRs were missing, so I've folded them into both — the multiple-label cases into #5170 and the arialabelledbyText/labelVirtual cases into #5171 — each Co-authored-by you.

Since the code's already covered, this PR will likely be closed as redundant once #5170/#5171 land — but I'll leave that call (and how we close out #4943) to @straker, who's coordinating the ElementInternals work. Either way, your tests live on in those PRs. Thanks again!

@straker

straker commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Since this work was pulled into other prs I'm going to close this one. Thanks for contributing.

@straker straker closed this Jul 14, 2026
@jcfranco
jcfranco deleted the 4943-include-ariaLabelledByElements-in-label-resolution branch July 14, 2026 14:50
chutchins25 added a commit that referenced this pull request Jul 17, 2026
Add consumer-level tests for the reflected ariaLabelledByElements property
(precedence over aria-labelledby and aria-label) in arialabelledbyText and
labelVirtual. getResolvedRefs already honors the property; this regression-
tests the #4943 scenario. Tests adapted from #5187.

Co-authored-by: JC Franco <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

label: should check ariaLabelledByElements as well

7 participants