fix(default-legend-content): add aria-label to legend icons#5414
Merged
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 3.x #5414 +/- ##
=======================================
Coverage 95.19% 95.19%
=======================================
Files 170 170
Lines 17609 17615 +6
Branches 3735 3735
=======================================
+ Hits 16763 16769 +6
Misses 840 840
Partials 6 6 ☔ View full report in Codecov by Sentry. |
PavelVanecek
approved these changes
Jan 2, 2025
PavelVanecek
pushed a commit
that referenced
this pull request
Jun 29, 2026
…el (#7501) The legend icon's `aria-label` is built as `${entry.value} legend icon`. When a series has no `name` and a function `dataKey`, `getTooltipNameProp` returns `undefined`, so the label becomes the literal string "undefined legend icon" and a screen reader reads out "undefined". The legend item renders no visible text in that case, so the accessible name no longer matches what is shown. The fix guards the value: when it is missing the label is just "legend icon", otherwise it is unchanged. Small follow-up to #5414 (which added the label) and #7109 (which kept it on the raw value). I added a test that renders `<Line dataKey={row => row.value} />` with no name. Before the change the icon's aria-label was "undefined legend icon"; after it is "legend icon". The full `Legend.spec` suite still passes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved legend accessibility labels so icon descriptions now fall back to a generic label when no entry value is available. * Prevented empty or confusing labels for legend items when a name is missing. * **Tests** * Added coverage for legend behavior when entries lack a name and use a non-string data key. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: greymoth-jp <[email protected]>
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
add an aria label to make accessibility scanners behave
Related Issue
#5412
Motivation and Context
accessibility
How Has This Been Tested?
assert this label is there, scanner no longer calls this an issue
Screenshots (if appropriate):
Types of changes
Checklist: