Keep tabs menu focus when using up/down (#5346)

This commit is contained in:
windingwind 2025-10-08 21:33:45 +02:00 • committed by GitHub
parent 46f879dcdb
commit cc4c8cd191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -356,6 +356,21 @@
this.resetFocus();
}
cacheFocus() {
if (this._selectedIndex === 0) {
// The first tab row does not have focusable elements
return;
}
let activeElement = document.activeElement;
if (this.contains(activeElement)) {
if (activeElement.classList.contains("close")) {
this._prevFocusClass = "close";
return;
}
}
this._prevFocusClass = null;
}
resetFocus() {
let row = this._tabsList.querySelector(".selected");
if (this._prevFocusClass) {
@ -464,14 +479,17 @@
_handleKeydown = (event) => {
if (["Home", "PageUp"].includes(event.key)) {
event.preventDefault();
this.cacheFocus();
this.moveSelection("first");
}
else if (["End", "PageDown"].includes(event.key)) {
event.preventDefault();
this.cacheFocus();
this.moveSelection("last");
}
else if (["ArrowUp", "ArrowDown"].includes(event.key)) {
event.preventDefault();
this.cacheFocus();
if (event.key == "ArrowDown") {
this.moveSelection("next");
}
@ -497,8 +515,8 @@
event.preventDefault();
event.stopPropagation();
// Move selection to the next tab to make sure the next tab's close button is focused
this.cacheFocus();
this.moveSelection("next");
this._prevFocusClass = "close";
this._handleCloseClick(event);
}
}