From c7e7dbf9847fca551fea960d9cfed4f7cae5bf9b Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 10 Oct 2026 18:01:08 +0200 Subject: [PATCH] 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 --- src/lib/components/common/Dropdown.svelte | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/components/common/Dropdown.svelte b/src/lib/components/common/Dropdown.svelte index ef83b07f01..75699ce553 100644 --- a/src/lib/components/common/Dropdown.svelte +++ b/src/lib/components/common/Dropdown.svelte @@ -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) {