Skip to content

fix(default-legend-content): add aria-label to legend icons#5414

Merged
ckifer merged 1 commit into
3.xfrom
add-title-to-legend-icon
Jan 2, 2025
Merged

fix(default-legend-content): add aria-label to legend icons#5414
ckifer merged 1 commit into
3.xfrom
add-title-to-legend-icon

Conversation

@ckifer

@ckifer ckifer commented Jan 2, 2025

Copy link
Copy Markdown
Member

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

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or extended an existing story to show my changes

@codecov

codecov Bot commented Jan 2, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.19%. Comparing base (bdfb24a) to head (fddee26).
Report is 1 commits behind head on 3.x.

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.
📢 Have feedback on the report? Share it here.

@ckifer
ckifer merged commit 84e71b0 into 3.x Jan 2, 2025
@ckifer
ckifer deleted the add-title-to-legend-icon branch January 2, 2025 23:57
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]>
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