Skip to content

Commit bdbe7a1

Browse files
github-actions[bot]KB Bot
authored andcommitted
Added new kb article htmlchart-keyboard-accessibility-for-series-items (#664)
Co-authored-by: KB Bot <[email protected]>
1 parent 6a9100b commit bdbe7a1

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Enabling Keyboard Accessibility for RadHtmlChart Series
3+
description: Learn how to make RadHtmlChart series focusable and clickable via the Enter key for keyboard navigation and accessibility.
4+
type: how-to
5+
page_title: Making RadHtmlChart Bar Series Accessible with Keyboard
6+
slug: htmlchart-keyboard-accessibility-for-series-items
7+
tags: radhtmlchart, accessibility, keyboard, focus, click, asp.net ajax
8+
res_type: kb
9+
ticketid: 1680317
10+
---
11+
12+
## Description
13+
14+
In web development, ensuring accessibility for all users, including those relying on keyboard navigation, is crucial. This knowledge base article provides a guide on making the series in a RadHtmlChart focusable and clickable via the Enter key. This functionality is essential for implementing drill-down features accessible through keyboard navigation, in line with WCAG 2.1 guidelines.
15+
16+
This knowledge base article also answers the following questions:
17+
- How can I make the RadHtmlChart series focusable using keyboard navigation?
18+
- How do I enable clicking on RadHtmlChart series with the Enter key for drill-down functionality?
19+
- What are the steps to achieve keyboard accessibility for RadHtmlChart in ASP.NET AJAX applications?
20+
21+
## Solution
22+
23+
To enable keyboard navigation and accessibility for the RadHtmlChart series, follow these steps:
24+
25+
1. Ensure each bar in the RadHtmlChart is focusable by setting its `tabindex` to `"0"`.
26+
2. Add a keydown event listener to each focusable bar.
27+
3. In the event listener, check if the Enter key is pressed. If so, manually trigger the desired click action.
28+
29+
### Updated JavaScript Code
30+
31+
````JavaScript
32+
function onChartLoad(sender, args) {
33+
setTimeout(function () {
34+
var chart = $find("<%= AssetRadChart.ClientID %>");
35+
if (chart) {
36+
var kendoChart = chart.get_kendoWidget ? chart.get_kendoWidget() : null;
37+
if (kendoChart) {
38+
var bars = kendoChart.element.find("svg path[fill]:not([fill='none'])");
39+
if (bars.length > 0) {
40+
bars.attr("tabindex", "0"); // Make bars focusable
41+
bars.first().focus();
42+
43+
// Add keydown event listener to make bars clickable via Enter key
44+
bars.on('keydown', function (e) {
45+
if (e.key === 'Enter') {
46+
var seriesIndex = $(this).index();
47+
var dataItem = kendoChart.dataSource.view()[seriesIndex];
48+
var sender = {
49+
series: { field: kendoChart.options.series[seriesIndex].field },
50+
dataItem: dataItem
51+
};
52+
OnClientSeriesClicked(sender);
53+
}
54+
});
55+
}
56+
}
57+
}
58+
}, 1000);
59+
}
60+
````
61+
62+
### Explanation
63+
64+
- **Tabindex:** By setting `tabindex="0"`, the SVG path elements become focusable, allowing for navigation through chart bars using the Tab key.
65+
- **Keydown Event:** The keydown event listener on each bar checks for the Enter key press (`e.key === 'Enter'`).
66+
- **Simulate Click:** Upon detecting the Enter key press, the code constructs a `sender` object, mimicking the one during a mouse click, and invokes the `OnClientSeriesClicked` function.
67+
68+
Implementing this solution will make the RadHtmlChart series not only focusable but also clickable via the Enter key, enhancing accessibility in compliance with WCAG 2.1 guidelines.
69+
70+
## See Also
71+
72+
- [RadHtmlChart Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/overview)
73+
- [Keyboard Accessibility in Web Applications](https://www.w3.org/WAI/standards-guidelines/wcag/)

0 commit comments

Comments
 (0)