I have a Chart component, created with Highcharts, which looks like this:
<div className={scss.chartContainer}>
{!hideContextMenu && (
<div className={scss.contextMenu}>
<ChartContextMenu
contextMenuLabel={`${contextMenuForLabel} ${defaultChartTitle}`}
enhancedContrastState={[a11yModeEnabled, toggleA11yMode]}
enhancedContrastLabel={contextMenuEnhancedContrastLabel}
enhancedContrastTooltip={contextMenuEnhancedContrastTooltip}
tableViewState={[showDataTable, setShowDataTable]}
tableViewLabel={contextMenuTableViewLabel}
tableViewTooltip={contextMenuTableViewTooltip}
/>
</div>
)}
<HighchartsReact
containerProps={{
"data-component": "chart",
"data-observe-key": props["data-observe-key"],
className: className,
style: style,
}}
highcharts={Highcharts}
options={chartOptions}
ref={chartComponentRef}
/>
</div>
Which looks like this (the ChartContextMenu
is the cogwheel button on the right)
Ok, so to my problem: Currently, in terms of accessibility, the keyboard navigation is:
- Cogwheel button
- Legend
- Series
And that totally makes sense, because the div order (ChartContextMenu
is before the chart), and the keyboard navigation within Highcharts is
keyboardNavigation: {
order: ["legend", "series"],
},
But I require to change this order, making the legend as 1st, followed by the cogwheel button, and last the series. How can I change this order? Like, I need to put a div that is outside the actual chart in the middle of the chart order Required order: 1. Legend 2. Cogwheel button 3. Series
I have tried using tabIndex
attribute within the divs to test it, but couldn't find a way to make it work..
Edit: I'm trying to follow the example from Highcharts API about Accessibility Custom Components, but I'm having some trouble with it: Example: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/accessibility/custom-component
My code:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const HighchartsContextMenu = function (this: any, chart: any) {
this.initBase(chart);
return (
<>
{!hideContextMenu && (
<div className={scss.contextMenu}>
<ChartContextMenu
contextMenuLabel={`${contextMenuForLabel} ${defaultChartTitle}`}
enhancedContrastState={[a11yModeEnabled, toggleA11yMode]}
enhancedContrastLabel={contextMenuEnhancedContrastLabel}
enhancedContrastTooltip={contextMenuEnhancedContrastTooltip}
tableViewState={[showDataTable, setShowDataTable]}
tableViewLabel={contextMenuTableViewLabel}
tableViewTooltip={contextMenuTableViewTooltip}
/>
</div>
)}
</>
);
};
HighchartsContextMenu.prototype = new Highcharts.AccessibilityComponent();
const element = (
<>
<SrOnly>
<Link href={`#${skipChartAnchorId}`}>{i18n.skipChart}</Link>
</SrOnly>
<div className={scss.chartContainer}>
<HighchartsContextMenu />
<HighchartsReact
containerProps={{
"data-component": "chart",
"data-observe-key": props["data-observe-key"],
className: className,
style: style,
}}
highcharts={Highcharts}
options={chartOptions}
ref={chartComponentRef}
/>
</div>
in the options:
accessibility: {
landmarkVerbosity: "disabled",
point: {
dateFormat: "%B %e, %Y",
},
screenReaderSection: {
beforeChartFormat: beforeChartFormatTemplate,
onViewDataTableClick: undefined,
},
customComponents: {
chartContextMenu: ChartContextMenu,
},
keyboardNavigation: {
order: ["legend", "chartContextMenu", "series"],
},
},
The error:
TypeError: this is undefined
Also, talking about the example, they create some functions extending Highcharts to config the button.. but since it's a custom component, do I have to do that as well? I'm kinda lost on this one