Skip to content

UI: Fix tab navigation after closing addon panel#33971

Draft
Copilot wants to merge 3 commits intonextfrom
copilot/fix-tab-navigation-bug
Draft

UI: Fix tab navigation after closing addon panel#33971
Copilot wants to merge 3 commits intonextfrom
copilot/fix-tab-navigation-bug

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Closing the addon panel (via close button or Alt+A shortcut) left focus on the now-removed DOM element, breaking keyboard navigation entirely.

After hiding the panel, focus is now moved to the "Show addon panel" toolbar button, but only when focus was within the panel at the time of closing. If the toolbar button is unavailable, focus falls back to the start of the document. When focus is elsewhere in the app (e.g. sidebar, toolbar, preview), it is left untouched.

  • layout.ts: Added showAddonPanel to focusableUIElements; added focusOnUIElement to SubAPI type; refactored focusOnUIElement to accept an options object with optional poll flag (defaults to true for backwards compatibility) and return boolean | Promise<boolean> indicating focus success
  • addons.tsx: Added id="storybook-show-addon-panel" to the toolbar button
  • container/Panel.tsx: toggleVisibility now calls focusOnUIElement with { poll: false } when hiding, falling back to document.body.focus() on failure; uses focusableUIElements.showAddonPanel constant
  • shortcuts.ts: togglePanel shortcut handler checks if focus was within the panel before moving it; uses { poll: false } and falls back to document.body.focus()
  • layout.test.ts: Added 10 unit tests for focusOnUIElement covering all code paths (no elementId, immediate focus, select options, poll/no-poll, polling success/timeout)

Manual testing

Prerequisites: Run yarn storybook:ui and open the Storybook UI in a browser.

Test 1 – Close addon panel via close button, focus moves to toolbar button

  1. Open the Storybook UI with the addon panel visible (default state).
  2. Using the keyboard (Tab), navigate to the "Hide addon panel" close button (✕) in the addon panel header.
  3. Press Enter or Space to close the addon panel.
  4. Verify that focus moves to the "Show addon panel" button in the toolbar.
  5. Press Tab and verify that keyboard navigation continues normally from the toolbar.

Test 2 – Close addon panel via keyboard shortcut while focus is in the panel

  1. Open the Storybook UI with the addon panel visible.
  2. Using the keyboard, navigate to any element inside the addon panel (e.g. an addon tab, the close button, the position toggle button).
  3. Press the keyboard shortcut to toggle the panel (default: A).
  4. Verify that focus moves to the "Show addon panel" button in the toolbar.
  5. Press Tab and verify that keyboard navigation continues normally.

Test 3 – Toggle panel via keyboard shortcut while focus is outside the panel

  1. Open the Storybook UI with the addon panel visible.
  2. Click on the sidebar (or any element outside the addon panel) to place focus there.
  3. Press the keyboard shortcut to toggle the panel (A).
  4. Verify that focus does not move — it stays wherever it was before (e.g. in the sidebar).
  5. Press Tab and verify that keyboard navigation continues normally from the current focus position.

Test 4 – Re-open addon panel after closing

  1. Close the addon panel using any method (close button or shortcut).
  2. Verify the "Show addon panel" button appears in the toolbar.
  3. Click or activate the "Show addon panel" button.
  4. Verify the addon panel re-opens and functions normally.
  5. Verify keyboard navigation works correctly with the panel re-opened.

Test 5 – Toggle panel shortcut when panel is already hidden

  1. Close the addon panel so it is hidden.
  2. Press the keyboard shortcut (A) to toggle the panel.
  3. Verify the panel opens and focus is not unexpectedly moved.
  4. Press Tab and verify keyboard navigation works normally.

Test 6 – Existing search shortcut still works

  1. Press the search shortcut (default: /) to focus the search field.
  2. Verify that the search field receives focus and the select behavior works (text is selected).
  3. Press Escape to close search, then press / again — verify polling still works for the search field focus.
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Tab navigation is broken after closing the addon panel</issue_title>
<issue_description>### Describe the bug

screenshare_-_2025-09-30_2_50_45_pm.mp4

We should address this by repositioning focus (at the start of the toolbar? start of the page? on the button in the toolbar for showing the toolbar?) and/or actually removing the panel instead of hiding it.

Reproduction link

yarn storybook:ui

Reproduction steps

  1. Go to the close addon panel button with kb
  2. Close the panel
  3. Press tab

System

SB 9 and 10

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@Sidnioulz > [@Sidnioulz](https://github.com/Sidnioulz)?target=https://github.com , can i work on this issue?

We don't assign issues, but you're free to start working on it on your own. See https://storybook.js.org/docs/contribute/code to get started.

Please refrain from pinging people on multiple tickets at the same time too. This causes a bit of email spam for the issue authors and the team. Thanks!</comment_new>
<comment_new>@Sidnioulz
Note that for this one, we haven't actually decided where focus should land when the addon panel is closed. My first guess would be to target the toolbar button that reopens it, and if the toolbar is also closed, to target the start of the document.</comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…panel

When the addon panel is closed via the close button or keyboard shortcut
(Alt+A), focus is now moved to the "Show addon panel" button in the
toolbar. This uses the existing focusOnUIElement polling mechanism to
handle the timing of React re-renders.

Fixes broken tab navigation after closing the addon panel.

Co-authored-by: Sidnioulz <5108577+Sidnioulz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tab navigation after closing addon panel Fix tab navigation broken after closing addon panel Mar 2, 2026
- Make focusOnUIElement polling optional via { poll: false } option
- Return boolean (sync) or Promise<boolean> (when polling) for success
- Maintain backwards compat with boolean 2nd arg for select option
- Only move focus when it was within the panel (shortcuts.ts)
- Fall back to document.body.focus() when showAddonPanel button unavailable
- Use focusableUIElements.showAddonPanel constant in container/Panel.tsx
- Add 10 unit tests for focusOnUIElement covering all code paths

Co-authored-by: Sidnioulz <5108577+Sidnioulz@users.noreply.github.com>
@Sidnioulz Sidnioulz changed the title Fix tab navigation broken after closing addon panel UI: Fix tab navigation after closing addon panel Mar 3, 2026
@Sidnioulz Sidnioulz self-requested a review March 3, 2026 10:13
@nx-cloud
Copy link

nx-cloud bot commented Mar 3, 2026

View your CI Pipeline Execution ↗ for commit 787a74c

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 11m 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-03 10:26:41 UTC

@nx-cloud
Copy link

nx-cloud bot commented Mar 3, 2026

View your CI Pipeline Execution ↗ for commit 787a74c


☁️ Nx Cloud last updated this comment at 2026-03-03 10:13:27 UTC

@nx-cloud
Copy link

nx-cloud bot commented Mar 3, 2026

View your CI Pipeline Execution ↗ for commit 787a74c

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ⏳ In Progress ... View ↗

☁️ Nx Cloud last updated this comment at 2026-03-03 10:24:35 UTC

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Fails
🚫 PR description is missing the mandatory "#### Manual testing" section. Please add it so that reviewers know how to manually test your changes.

Generated by 🚫 dangerJS against 787a74c

@Sidnioulz
Copy link
Member

@copilot give a comprehensive list of manual testing steps in the PR description under heading "#### Manual testing"; this is a mandatory CI requirement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Tab navigation is broken after closing the addon panel

2 participants