Skip to content

Commit 9dcad7f

Browse files
committed
WebUI: Fix keyboard navigation when using virtual rendering
1 parent 76990fd commit 9dcad7f

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
@@ -963,6 +963,7 @@ window.qBittorrent.DynamicTable ??= (() => {
963963
element = this.cachedElements[position] = this.createRowElement(row, offset);
964964
elements.push(element);
965965
}
966+
const hadFocus = this.dynamicTableDiv.contains(document.activeElement);
966967
this.tableBody.replaceChildren(...elements);
967968

968969
// update row classes
@@ -971,6 +972,10 @@ window.qBittorrent.DynamicTable ??= (() => {
971972
// update visible rows
972973
for (const row of this.tableBody.children)
973974
this.updateRow(row, true);
975+
976+
// restore focus so keyboard navigation continues working
977+
if (hadFocus)
978+
this.getTrByRowId(this.getSelectedRowId())?.focus({ preventScroll: true });
974979
}
975980

976981
createRowElement(row, top = -1) {
@@ -1082,6 +1087,7 @@ window.qBittorrent.DynamicTable ??= (() => {
10821087
this.deselectAll();
10831088
const newRow = visibleRows[selectedIndex + 1];
10841089
this.selectRow(newRow.getAttribute("data-row-id"));
1090+
newRow.focus({ preventScroll: true });
10851091
}
10861092
}
10871093

@@ -1096,6 +1102,7 @@ window.qBittorrent.DynamicTable ??= (() => {
10961102
this.deselectAll();
10971103
const newRow = visibleRows[selectedIndex - 1];
10981104
this.selectRow(newRow.getAttribute("data-row-id"));
1105+
newRow.focus({ preventScroll: true });
10991106
}
11001107
}
11011108
}
@@ -2441,17 +2448,23 @@ window.qBittorrent.DynamicTable ??= (() => {
24412448
return;
24422449

24432450
const node = this.getNode(id);
2444-
if (node.isFolder)
2451+
if (node.isFolder) {
24452452
this.expandNode(node.rowId);
2453+
if (this.useVirtualList)
2454+
this.rerender();
2455+
}
24462456
}
24472457

24482458
collapseFolder(id) {
24492459
if (!this.supportCollapsing)
24502460
return;
24512461

24522462
const node = this.getNode(id);
2453-
if (node.isFolder)
2463+
if (node.isFolder) {
24542464
this.collapseNode(node.rowId);
2465+
if (this.useVirtualList)
2466+
this.rerender();
2467+
}
24552468
}
24562469

24572470
isAllCheckboxesChecked() {

0 commit comments

Comments
 (0)