Make GlChartLegend series rows keyboard operable
What does this MR do?
Makes the series rows in GlChartLegend keyboard operable.
Each series row was a <div role="button"> with only a click handler, no tabindex and no key handler. Keyboard and screen reader users could not focus a row or toggle a series with Enter or Space, which fails WCAG 2.1.1 Keyboard (Level A). For GlLineChart, GlAreaChart, GlStackedColumnChart and GlHeatmap, the legend is the only way to toggle a series, so these users had no way to do it at all.
This MR:
- Renders each series row as a native
<button type="button">in both the inline and tabular layouts. This makes each row focusable and lets Enter and Space toggle it, with the correct role. - Adds
aria-pressedso screen readers announce whether each series is shown or hidden. - Keeps
aria-disabledrather thandisabledfor series that can't be toggled (the last visible series, or a series withdisabled: true), so they stay focusable and are still announced. - Aligns
aria-disabledin the tabular layout with the inline layout. The tabular layout didn't mark the row as disabled when there is only one series. - Adds a focus ring and resets the native button styles, so the legend looks the same as before.
The focus ring uses the gl-focus SCSS mixin with $inset: true instead of the focus-visible:gl-focus-inset utility. The utility sets outline: none with no fallback, so the ring would disappear in forced-colors mode (Windows High Contrast). The mixin adds an outline in that mode. The inset variant also keeps the ring from being clipped by the tabular layout's scroll container.
Closes #3652 (closed)
How to test
- Open the
charts/chart-legendstories in this MR's review app. - Press Tab to move through the legend. Each series row receives a visible focus ring.
- Press Enter or Space on a row. The series hides and shows in the chart, and
aria-pressedchanges betweentrueandfalse. - Repeat in With Tabular Layout And Disabled Legend Item. The disabled row is focusable, has
aria-disabled="true", and does not toggle.
Screenshots or screen recordings
| Layout | Focused row |
|---|---|
| Inline | ![]() |
| Tabular | ![]() |
Integrations
Legend rows no longer have role="button". Any selector in consuming projects that finds legend rows with [role="button"] needs to use button instead.
- GitLab: mr_url
- CustomersDot: mr_url
- Duo UI: mr_url
- Status Page: mr_url
- Docs: mr_url
- Switchboard: mr_url

