feat: resolve analytics label from associated <label for> element#228
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
pan-kot
approved these changes
Jul 10, 2026
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.
Description
getLabelFromElementnow resolves the text of an associatedlabel[for="id"]when the element has no accessible name of its own. Resolution order becomes:aria-label→aria-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 anaria-*attribute or child text). AbstractSwitch already points itsdetail.labelselector at the native<input>when used without alabelprop — 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 emitselect/deselectevents with an empty label.Testing
<label for>;aria-labelstill takes precedence.npm run test:unit(analytics-metadata),npm run build,npm run lintall pass.