Skip to content

feat: resolve analytics label from associated <label for> element#228

Merged
gethinwebster merged 1 commit into
mainfrom
dev-gethinw-label-for-analytics
Jul 10, 2026
Merged

feat: resolve analytics label from associated <label for> element#228
gethinwebster merged 1 commit into
mainfrom
dev-gethinw-label-for-analytics

Conversation

@gethinwebster

Copy link
Copy Markdown
Member

Description

getLabelFromElement now resolves the text of an associated label[for="id"] when the element has no accessible name of its own. Resolution order becomes: aria-labelaria-labelledby<label for>textContent.

Motivation

Autocapture analytics can't resolve a label for controls whose accessible name is bound only via an external <label for> (rather than an aria-* attribute or child text). AbstractSwitch already points its detail.label selector at the native <input> when used without a label prop — but that input has no aria/text of its own, so the label resolved to ''. The most visible case is CollectionPreferences visible-content column toggles, which currently emit select/deselect events with an empty label.

Testing

  • Added unit tests: resolves via <label for>; aria-label still takes precedence.
  • npm run test:unit (analytics-metadata), npm run build, npm run lint all pass.

getLabelFromElement now falls back to the text of a `label[for=id]` associated with the element (after aria-label/aria-labelledby, before textContent). This lets autocapture resolve a label for controls whose accessible name is bound only via an external <label for> — e.g. CollectionPreferences visible-content toggles, where AbstractSwitch already points detail.label at the native input.
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.00%. Comparing base (cce49df) to head (9e877b7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #228   +/-   ##
=======================================
  Coverage   99.00%   99.00%           
=======================================
  Files          44       44           
  Lines        1307     1313    +6     
  Branches      363      364    +1     
=======================================
+ Hits         1294     1300    +6     
  Misses         12       12           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gethinwebster gethinwebster added this pull request to the merge queue Jul 10, 2026
Merged via the queue into main with commit 78240a2 Jul 10, 2026
44 checks passed
@gethinwebster gethinwebster deleted the dev-gethinw-label-for-analytics branch July 10, 2026 08:50
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.

2 participants