From c22afbbbdb282024234a96acab263a299e43ce69 Mon Sep 17 00:00:00 2001 From: Steve Dodier-Lazaro Date: Mon, 16 Mar 2026 20:21:37 +0100 Subject: [PATCH] UI: Use correct selector for addon panel focus check --- code/core/src/manager-api/modules/shortcuts.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/core/src/manager-api/modules/shortcuts.ts b/code/core/src/manager-api/modules/shortcuts.ts index 7895ec219f8a..58f352467407 100644 --- a/code/core/src/manager-api/modules/shortcuts.ts +++ b/code/core/src/manager-api/modules/shortcuts.ts @@ -16,6 +16,10 @@ import { focusableUIElements } from './layout'; const { navigator, document } = global; +function wasFocusInElement(element: HTMLElement | null) { + return document.activeElement && element?.contains(document.activeElement); +} + export const isMacLike = () => navigator && navigator.platform ? !!navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) : false; export const controlOrMetaKey = () => (isMacLike() ? 'meta' : 'control'); @@ -359,13 +363,11 @@ export const init: ModuleFn = ({ store, fullAPI, provider }) => { case 'togglePanel': { const wasPanelShown = fullAPI.getIsPanelShown(); - const panelElement = document.getElementById(focusableUIElements.storyPanelRoot); - const wasFocusInPanel = - panelElement && document.activeElement && panelElement.contains(document.activeElement); + const panelElement = document.getElementById(focusableUIElements.addonPanel); fullAPI.togglePanel(); - if (wasPanelShown && wasFocusInPanel) { + if (wasPanelShown && wasFocusInElement(panelElement)) { // poll: true always returns a Promise. ( fullAPI.focusOnUIElement(focusableUIElements.showAddonPanel, { @@ -384,11 +386,10 @@ export const init: ModuleFn = ({ store, fullAPI, provider }) => { case 'toggleNav': { const wasNavShown = fullAPI.getIsNavShown(); const sidebarElement = document.getElementById(focusableUIElements.sidebarRegion); - const wasFocusInSidebar = sidebarElement?.contains(document?.activeElement); fullAPI.toggleNav(); - if (wasNavShown && wasFocusInSidebar) { + if (wasNavShown && wasFocusInElement(sidebarElement)) { // poll: true always returns a Promise. ( fullAPI.focusOnUIElement(focusableUIElements.showSidebar, {