Skip to content

Commit 54dee18

Browse files
committed
WebUI: Fix keyboard navigation when using virtual rendering
1 parent 4255d4a commit 54dee18

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/webui/www/private/scripts/dynamicTable.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ window.qBittorrent.DynamicTable ??= (() => {
977977
element = this.cachedElements[position] = this.createRowElement(row, offset);
978978
elements.push(element);
979979
}
980+
const hadFocus = this.dynamicTableDiv.contains(document.activeElement);
980981
this.tableBody.replaceChildren(...elements);
981982

982983
// update row classes
@@ -985,6 +986,10 @@ window.qBittorrent.DynamicTable ??= (() => {
985986
// update visible rows
986987
for (const row of this.tableBody.children)
987988
this.updateRow(row, true);
989+
990+
// restore focus so keyboard navigation continues working
991+
if (hadFocus)
992+
this.getTrByRowId(this.getSelectedRowId())?.focus({ preventScroll: true });
988993
}
989994

990995
createRowElement(row, top = -1) {
@@ -1096,6 +1101,7 @@ window.qBittorrent.DynamicTable ??= (() => {
10961101
this.deselectAll();
10971102
const newRow = visibleRows[selectedIndex + 1];
10981103
this.selectRow(newRow.getAttribute("data-row-id"));
1104+
newRow.focus({ preventScroll: true });
10991105
}
11001106
}
11011107

@@ -1110,6 +1116,7 @@ window.qBittorrent.DynamicTable ??= (() => {
11101116
this.deselectAll();
11111117
const newRow = visibleRows[selectedIndex - 1];
11121118
this.selectRow(newRow.getAttribute("data-row-id"));
1119+
newRow.focus({ preventScroll: true });
11131120
}
11141121
}
11151122
}
@@ -2506,17 +2513,23 @@ window.qBittorrent.DynamicTable ??= (() => {
25062513
return;
25072514

25082515
const node = this.getNode(id);
2509-
if (node.isFolder)
2516+
if (node.isFolder) {
25102517
this.expandNode(node.rowId);
2518+
if (this.useVirtualList)
2519+
this.rerender();
2520+
}
25112521
}
25122522

25132523
collapseFolder(id) {
25142524
if (!this.supportCollapsing)
25152525
return;
25162526

25172527
const node = this.getNode(id);
2518-
if (node.isFolder)
2528+
if (node.isFolder) {
25192529
this.collapseNode(node.rowId);
2530+
if (this.useVirtualList)
2531+
this.rerender();
2532+
}
25202533
}
25212534

25222535
isAllCheckboxesChecked() {

0 commit comments

Comments
 (0)