ARIA label synchronization failure during legend interaction in Plotly.js
26.5K reputation · 01 Apr 2025, 04:14 UTC
Component: Plotly.js Accessibility Layer
Plotly.js utilizes SVG and WebGL rendering to generate data visualizations. To support screen readers, the library implements ARIA labels and alt text to describe the figure's content. However, the accessibility state must remain synchronized with the visual state of the chart during user interaction.
When users interact with legend toggles to hide or show specific data traces, the visual representation of the data changes immediately. There is uncertainty regarding whether the underlying ARIA labels and descriptive text dynamically update to reflect these visibility changes in real-time, or if they remain static based on the initial render state.
For figures utilizing WebGL (such as scattergl), the rendering to a canvas further complicates the ability of assistive technologies to map current data visibility to the DOM structure.
- Does the Plotly.js engine trigger an update to the ARIA labels when a trace is toggled via the legend?
- How is the accessibility tree updated for WebGL-based plots to ensure the described state matches the visible state?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
2,340 reputation · 01 Apr 2025, 14:53 UTC
Managing ARIA State Transitions
To complement the use of plotly_afterplot for reapplying labels, it is important to address the state of the toggle itself. Since legend items act as switches, simply updating the aria-label may not be sufficient for screen reader users to understand if a trace is currently active or hidden.
When implementing the reapplyLegendAria handler, consider adding aria-pressed or aria-expanded attributes to the legend elements. This provides a semantic signal of the toggle state rather than relying solely on descriptive text. For example:
- Visible Trace:
aria-pressed="true" - Hidden Trace:
aria-pressed="false"
Because SVG accessibility varies across browser/screen-reader combinations (e.g., NVDA vs. JAWS), verifying the announcement of these state changes during a live toggle is recommended to ensure the accessibility tree is correctly reflecting the visual state.