Skip to content

🐛 Prefer anchor and role="link" text over ancestor ARIA labels for RUM action names - #5013

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
DataDog:mainfrom
anakorn-wm:anakorn/prefer-anchor-text-in-action-name
Sep 14, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
DataDog:mainfrom
anakorn-wm:anakorn/prefer-anchor-text-in-action-name

Conversation

@anakorn-wm

Copy link
Copy Markdown
Contributor

Motivation

Addresses bug report #5007

getActionNameFromElement runs every priorityStrategies entry against the target and up to 10 ancestors before ever falling back to text content of the target. When an anchor sits inside an ancestor with an aria-label or aria-labelledby (for example a role="dialog" whose aria-labelledby points at a visually-hidden title), RUM records the ancestor's label as the action name instead of the visible anchor text the user actually clicked.

This is common with accessible dialog primitives that require a title element on the dialog root, and it produces surprising click names like click on This is a modal window on every anchor inside the modal.

Changes

The ("BUTTON, LABEL or button-like element text") priority strategy now also matches <a> and role="link", mirroring the existing symmetry with <button> and role="button". The text content of the clicked anchor is picked at iteration 0 of the walk, so ancestor ARIA attributes no longer beat it.

Behavior change to flag: an <a> (or role="link") that carries both a visible text label and its own aria-label will now resolve to the visible text instead of the aria-label. That matches how <button> has always worked, but any team relying on the previous behavior will see a name shift. Not gated behind a config flag but happy to do so if desired.

Test instructions

yarn test:unit --spec packages/browser-rum-core/src/domain/action/getActionNameFromElement.spec.ts

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@anakorn-wm

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@bdibon
bdibon marked this pull request as ready for review September 11, 2026 07:42
@bdibon
bdibon requested a review from a team as a code owner September 11, 2026 07:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T07:46:35.119314Z 3d70317 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d7031770d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +100 to +102
element.nodeName === 'A' ||
element.getAttribute('role') === 'button' ||
element.getAttribute('role') === 'link'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep each link's own ARIA label ahead of its text

issue: When an <a> or role="link" has both text and its own aria-label or aria-labelledby (for example, <a aria-label="Close">×</a>), this widened strategy now returns the text before reaching the later ARIA strategies, changing the recorded action name from Close to ×. Handle links in a separate strategy after the two ARIA strategies; their text will still be selected before walking to an ancestor, without overriding the link's own accessible name.

Useful? React with 👍 / 👎.

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.

It's coherent with the "button" case. We might consider later to follow more closely the accname spec.

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Sep 11, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 77.01% (-0.06%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 93a80e2 | Docs | View more details | Give us feedback!

@anakorn-wm
anakorn-wm force-pushed the anakorn/prefer-anchor-text-in-action-name branch from 3d70317 to 93a80e2 Compare September 11, 2026 17:03
@anakorn-wm

Copy link
Copy Markdown
Contributor Author

Thanks for the review @bdibon. FYI I've amended my original commit in this PR with a signature given the branch protection rule ("commits must have verified signatures").

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Possible bug] getActionNameFromElement is preferring an anchor's ancestor aria-label over the anchor's text content

2 participants