fix(DefaultLegendContent): omit empty value from legend icon aria-label#7501
Conversation
WalkthroughIn Legend icon aria-label null fallback
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/component/DefaultLegendContent.tsx`:
- Line 241: Treat empty legend names as missing in DefaultLegendContent so the
aria-label falls back to the icon-only text instead of producing a leading
space. Update the aria-label logic around entry.value to handle both
null/undefined and empty-string values, and add a Legend spec covering
getTooltipNameProp('')/empty legend names to verify the behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3a7b79e0-9198-4416-afdc-69c3986bf3aa
📒 Files selected for processing (2)
src/component/DefaultLegendContent.tsxtest/component/Legend.spec.tsx
| viewBox={viewBox} | ||
| style={svgStyle} | ||
| aria-label={`${entry.value} legend icon`} | ||
| aria-label={entry.value == null ? 'legend icon' : `${entry.value} legend icon`} |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== find getTooltipNameProp implementation =="
rg -n -C3 '\bgetTooltipNameProp\b' src test
echo
echo "== find legend aria-label tests =="
rg -n -C2 "legend icon|aria-label drops the value|undefined legend icon" test src/component
echo
echo "== inspect changed legend rendering block =="
sed -n '232,245p' src/component/DefaultLegendContent.tsxRepository: recharts/recharts
Length of output: 14467
Treat empty legend names as missing. getTooltipNameProp('', ...) returns '', so this renders " legend icon" instead of the icon-only label. Handle the empty-string case here and add a Legend spec for it. src/component/DefaultLegendContent.tsx:241
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/component/DefaultLegendContent.tsx` at line 241, Treat empty legend names
as missing in DefaultLegendContent so the aria-label falls back to the icon-only
text instead of producing a leading space. Update the aria-label logic around
entry.value to handle both null/undefined and empty-string values, and add a
Legend spec covering getTooltipNameProp('')/empty legend names to verify the
behavior.
Bundle ReportChanges will increase total bundle size by 104 bytes (0.0%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7501 +/- ##
=======================================
Coverage 88.13% 88.13%
=======================================
Files 608 608
Lines 14207 14208 +1
Branches 3564 3565 +1
=======================================
+ Hits 12521 12522 +1
Misses 1496 1496
Partials 190 190 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The legend icon's
aria-labelis built as${entry.value} legend icon. When a series has nonameand a functiondataKey,getTooltipNamePropreturnsundefined, 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 fullLegend.specsuite still passes.Summary by CodeRabbit
Bug Fixes
Tests