The plotly treemap does not come with the built-in accessibility feature and keyboard accessibility. This package adds the keyboard navigation on angular plotly treemap along with the content recognition by screen reader (tested on NVDA).
npm install plotly-a11y-enhancernpm i plotly-a11y-enhancer
TreemapInteractionService into your component where treemap is added
import { TreemapInteractionService } from 'plotly-a11y-enhancer';
TreemapInteractionService in your component.
constructor( private _interactionService: TreemapInteractionService,)
[data]="graph.data"
[layout]="graph.layout"
[config]="graph.config"
(afterPlot)="heatmapLoaded()">
`
Once treemap is loaded it calls the heatmapLoadedcallback.
Please add below code inside that function:
`
heatmapLoaded() {
this._interactionService.addKeyboardInteractions('plotly-plot');
}
`
And you are done.
Note: Make sure to call cleanUpListeners in ngOnDestroy to avoid any memory leaks.
`
ngOnDestroy() {
this._interactionService.cleanUpListeners(); // Note: This is important otherwise there will be memory leaks
}
``