fix: closing Settings opened from the user menu loses the keyboard focus (#32185)

Picking Settings from the user menu with the keyboard left the focus on the menu item, which disappears as the menu closes. When Settings closed, the focus went back to that removed item, so it was lost and the next Tab started over at the top of the page. The menu now gives the focus back to the user menu button when it closes after an item is picked, the same as when it is closed with Escape, so closing Settings returns there.

Fixes #32017
This commit is contained in:
Classic298 2026-10-10 18:01:08 +02:00 • committed by GitHub
parent 6faf540310
commit c7e7dbf984
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -275,6 +275,13 @@
previouslyFocused = null;
}
function restoreFocusAfterClose() {
if (contentEl?.contains(document.activeElement) && previouslyFocused?.isConnected) {
previouslyFocused.focus();
}
previouslyFocused = null;
}
function toggleOpen() {
if (show) {
closeDropdown();
@ -286,6 +293,8 @@
// React to external show changes (e.g. bind:show toggled by parent component)
$: if (show) {
afterOpen();
} else {
restoreFocusAfterClose();
}
function handleWindowClick(event: MouseEvent) {