
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
chartjs-plugin-a11y-legend
Advanced tools
Chart.js plugin to provide keyboard navigation to legends
Provide keyboard accessibility to the legends of your chart.js charts. When this plugin is activated, a user can press the TAB key to navigate to the legend. Once focused on a legend item, the user presses the left/right arrow keys to navigate between legend items. Then, they can press spacebar or enter to "click" the item.
Label, position, and selection state are also provided to screen reader users using aria attributes.
Add the plugin to your existing chart.js code like this:
import {Chart} from "chart.js/auto";
import plugin from "chartjs-plugin-a11y-legend";
Chart.register(plugin);
That will register the plugin globally. Alternatively, if you want to enable for a given chart, you can do this:
import {Chart} from "chart.js/auto";
import plugin from "chartjs-plugin-a11y-legend";
new Chart(canvasElement, {
type: "bar",
data: {
datasets: [{
data: [1,4,2,8]
}]
},
plugins: [plugin]
});
The following pluing options are available:
margin
- (pixels) Add some margin to the bounding box that will appear around your legend items. Default: 4
.Here's an example for adding your own options:
import {Chart} from "chart.js/auto";
import plugin from "chartjs-plugin-a11y-legend";
new Chart(canvasElement, {
type: "bar",
data: {
datasets: [{
data: [1,4,2,8]
}]
},
options: {
plugins: {
a11y_legend: {
margin: 0
}
}
},
plugins: [plugin]
});
The plugin will also work with react-chartjs-2.
import React from "react";
import {Chart, registerables} from "chart.js";
import {Bar} from "react-chartjs-2";
import a11yLegend from "chartjs-plugin-a11y-legend";
// Register what you want for chart.js
Chart.register(...registerables);e
// Register the a11y legend plugin, so that it can apply to every chart
Chart.register(a11yLegend);
// Here's a sample chart using react-chartjs-2
export default function App(){
return <>
<Bar
data={{
labels: ["A","B","C","D"],
datasets: [
{
label: "Green",
data: [9,3,5,1]
},
{
label: "Red",
data: [5,6,2,8]
}
]
}}
/>
</>
}
This plugin is currently in beta, so not all of the chart.js features are currently supported.
Chart types supported:
This plugin is tested with Windows + Chrome + NVDA. If you find issues with this plugin and any screen reader + browser combination, please open an issue.
The legend is added to the "tab order", meaning that when users press the TAB key to navigate a website, they'll be able to "tab" to the legends in your charts. They'll tab to the first item in the legend, and then they can press the left/right arrow keys to navigate between individual items in the legend. Users can also "click" the legend items by pressing enter or spacebar.
This UX is modeled after W3C's WAI-ARIA authoring practices guide for tabs and toolbars.
Check out this CodePen to see how the plugin works with all of chart.js's built-in chart types.
FAQs
Chart.js plugin to provide keyboard navigation to legends
The npm package chartjs-plugin-a11y-legend receives a total of 1,160 weekly downloads. As such, chartjs-plugin-a11y-legend popularity was classified as popular.
We found that chartjs-plugin-a11y-legend demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.