Skip to content

Commit 161f5f5

Browse files
github-actions[bot]KB Bot
and
KB Bot
authored
Added new kb article asyncupload-retain-focus-on-remove-button (#603)
Co-authored-by: KB Bot <[email protected]>
1 parent a7a6606 commit 161f5f5

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Retaining Focus on RadAsyncUpload's File List Post File Deletion
3+
description: Learn how to maintain keyboard focus on the RadAsyncUpload component's file list after removing a file using client-side events.
4+
type: how-to
5+
page_title: Retaining Focus on RadAsyncUpload's File List Post File Deletion
6+
slug: asyncupload-retain-focus-on-remove-button
7+
tags: radasyncupload, aspnet-ajax, keyboard, focus, client-side, event
8+
res_type: kb
9+
ticketid: 1666430
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>RadAsyncUpload for ASP.NET AJAX</td>
19+
</tr>
20+
<tr>
21+
<td>Version</td>
22+
<td>All</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
## Description
28+
29+
When removing a file from the [RadAsyncUpload](https://docs.telerik.com/devtools/aspnet-ajax/controls/asyncupload/overview) component using its Remove button, the keyboard focus is lost and doesn't automatically move to the next file's Remove button. This behavior requires pressing the Tab key again to focus on the next element in the list, which is not ideal for keyboard navigation. This KB article also answers the following questions:
30+
31+
- How can I keep the keyboard focus within the RadAsyncUpload's file list after removing a file?
32+
- Is it possible to automatically focus the next Remove button in RadAsyncUpload's file list?
33+
- Can client-side events be used to improve keyboard navigation in RadAsyncUpload?
34+
35+
## Solution
36+
37+
To resolve this issue and enhance keyboard navigation within the RadAsyncUpload component, leverage the `OnClientFileUploadRemoved` client-side event. This approach involves registering an event handler that focuses on the next available Remove button after a file is removed. Here's how to implement this solution:
38+
39+
1. Define the RadAsyncUpload control in your ASP.NET AJAX page with the `OnClientFileUploadRemoved` attribute pointing to a JavaScript function:
40+
41+
````ASP.NET
42+
<telerik:RadAsyncUpload ID="upload1" runat="server" OnClientFileUploadRemoved="onClientFileUploadRemoved" MultipleFileSelection="Automatic" />
43+
````
44+
45+
2. Implement the `onClientFileUploadRemoved` function in JavaScript. This function finds all Remove buttons and sets focus to the first one after a brief timeout, ensuring the focus transition happens smoothly:
46+
47+
````JavaScript
48+
function onClientFileUploadRemoved(sender, args) {
49+
let removeButtons = document.querySelectorAll(".ruRemove"); // Get all the "Remove" span elements
50+
51+
setTimeout(() => {
52+
removeButtons[0]?.focus(); // Focus the next one if it exists
53+
}, 10)
54+
}
55+
````
56+
57+
By implementing this client-side logic, you ensure that the keyboard focus remains within the RadAsyncUpload's file list, improving accessibility and usability for keyboard users.
58+
59+
## See Also
60+
61+
- [RadAsyncUpload Overview](https://docs.telerik.com/devtools/aspnet-ajax/controls/asyncupload/overview)
62+
- [OnClientFileUploadRemoved Event](https://docs.telerik.com/devtools/aspnet-ajax/controls/asyncupload/client-side-programming/onclientfileuploadremoved#onclientfileuploadremoved)

0 commit comments

Comments
 (0)