Skip to content

fix(web): return focus to closed popup trigger after command palette closes - #47034

Merged
juliusmarminge merged 3 commits into
pingdotgg:mainfrom
only21mil:fix/web-command-palette-focus-after-closed-popup
Dec 1, 2026
Merged

juliusmarminge merged 3 commits into
pingdotgg:mainfrom
only21mil:fix/web-command-palette-focus-after-closed-popup

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

When you open the command palette (Ctrl+K, or Ctrl+P then Escape back to commands) while a select popup is open and press Escape, focus drops to document.body instead of returning to the select's trigger.

CloseOpenPopups closes the select on open; Base UI keeps a closed Select mounted but hidden, so focusing its saved option silently fails.

Change

In apps/web/src/components/ui/command.tsx, CloseOpenPopups captures the outermost open popup's trigger in a layout effect before closeOpenPopups runs. On close, resolveFinalFocus keeps Base UI's external-focus guard when finalFocus is omitted or true (returning false if focus moved outside the palette to a non-body element), and leaves caller false/undefined suppression or any still-focusable target unchanged. It substitutes the captured trigger only when the caller resolves to true, null, document.body, or an unfocusable element and that trigger is focusable and closed; otherwise it passes the caller's target (or true) through so Base UI's default stands. Added one regression test in CommandPaletteContent.browser.test.tsx.

Scope

Small bug fix, no issue needed. Web and desktop (apps/web); mobile has no CommandDialogPopup.

Verification

Setup. Ubuntu 26.04, dark, 1280x800, fresh isolated data, Playwright Chromium CDP input.

Steps. /settings/general (direct route and modal over thread) → focus Thread notifications select → Space → Ctrl+K → Escape (or Ctrl+P → Escape × 2).

Before (afd9ee2014aa) After (5f83223f11f2)
Direct: focus on body
Direct: focus on body
Direct: focus on trigger
Direct: focus on trigger
Modal: focus on body
Modal: focus on body
Modal: focus on trigger
Modal: focus on trigger

Links. Base afd9ee2014aa, head 5f83223f11f2.

Not shown.

  • Menu, combobox, popover: menu and combobox checked on Linux Chromium already returned focus to their trigger on base; the fallback covers them, no fault shown.
  • macOS, Windows, Electron shell, mobile (no Base UI).
Automated checks and non-fault close paths
  • Real-app checks on afd9ee2014aa vs 5f83223f11f2:
    • /settings/general direct route, modal over thread, Ctrl+P → Escape × 2, and click-opened select: BODY → BUTTON[aria-label="Thread notifications"] (focusVisible: true).
    • Control (plain button General, no popup open) → Ctrl+K → Escape: BUTTON "General" unchanged.
    • Non-fault close paths unchanged: Open settings command, palette from inside Settings dialog → Escape (returns to Search settings), Change theme submenu → Escape, Ctrl+Shift+F → Escape × 2, thread-route Branch: main combobox → Ctrl+K → Escape (composer owns return focus), /pull-requests Projects combobox and Sort menu → Ctrl+K → Escape (returns to triggers).
  • Browser regression test (apps/web/src/components/CommandPaletteContent.browser.test.tsx):
    • Fails on afd9ee2014aa: 1 failed | 6 passed (7) (Received element with focus: <body>).
    • Passes on 5f83223f11f2: 7 passed (7) in 8.37s; 2 x 100 parallel stress loop (Node 26.13.1): 200/200 passed, 0 failed (loop_1: 100/100, loop_2: 100/100, 599s).
  • vp run check:changed afd9ee2014aaa3c7bf5d039e52640d1470e11e6a on 5f83223f11f2: format, lint, knip, typecheck (2 packages), test (7/7), and React Compiler all pass.

Generated with Gemini 4 Neon in T3 Code Nightly

…closes

When CommandDialogPopup opens while a Select popup (or another popup whose saved return target stays connected in a hidden portal or becomes unfocusable on close) is open, CloseOpenPopups closes that popup so it does not stay painted above the palette. Closing the palette with Escape then tried to restore focus to the now-hidden option inside the closed portal, silently failing and dropping focus to document.body.

Capture the outermost open popup's trigger before popups close and return it from CommandDialogPopup's finalFocus fallback when the caller's target is true, null, document.body, or an element that can no longer take focus, provided the trigger is still connected, enabled, visible, not inert, and closed. Otherwise pass the caller's result through unchanged and preserve Base UI's external-focus guard when finalFocus is omitted or true.
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Dec 1, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — The change restores focus to a closed popup’s trigger when the command palette closes. It also adds a lint-suppression directive in command.tsx:66, which requires human review under the configured policy.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The command palette now captures an open popup’s trigger and can use it as a fallback focus target when the palette closes. A browser test checks that Escape returns focus to the select trigger.

Changes: Focus Restoration

Layer / File(s) Summary
Capture and restore popup focus
apps/web/src/components/ui/command.tsx, apps/web/src/components/CommandPaletteContent.browser.test.tsx
CloseOpenPopups captures an open popup trigger. CommandDialogPopup resolves final focus using the configured target and captured trigger, while preserving focus suppression and the default behavior’s check against stealing focus. The browser test verifies that Escape returns focus to the select trigger.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge, koushikxd

Merge Risk: Minimal · up to 29182

This change returns focus to the select trigger after the command palette closes over an open select popup. No concrete merge-blocking risk was found. The change is small, reversible, and covered by a browser regression test.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix, the affected area (web), and the behavior: focus returns to the closed popup trigger after the command palette closes. This matches the main change in command.tsx, which subst…
Description check Passed The description follows the template sections (Problem, Change, Scope, Verification) and fills each one with specific content. The Problem section gives the bug, reproduction steps, and cause. The Cha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix, the affected area (web), and the behavior: focus returns to the closed popup trigger after the command palette closes. This matches the main change in command.tsx, which substitutes the captured trigger as the final focus target when the default target is invalid. The conventional commit format is used.

Full details: Description check

Explanation

The description follows the template sections (Problem, Change, Scope, Verification) and fills each one with specific content. The Problem section gives the bug, reproduction steps, and cause. The Change section explains the resolver logic in command.tsx and the added regression test. Scope explains why no issue is linked and names the affected platforms. Verification gives before/after screenshots, a browser regression test result that fails on base and passes on head, and the automated check results. It also states what was not tested (macOS, Windows, Electron, mobile). The template asks for a model and harness attribution at the end, and the description includes one (Gemini 4 Neon in T3 Code Nightly).

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5f83223 and 2918266.

Files selected for processing: 1

  • apps/web/src/components/ui/command.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 1, 2026
juliusmarminge and others added 2 commits December 1, 2026 21:23
Name why the default return keeps an activeElement check: wrapping
finalFocus in a function makes it explicit to Base UI, which then no
longer skips the return when focus already moved elsewhere.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:S 10-29 changed lines (additions + deletions). labels Dec 1, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

On each fresh app: open /settings/general; focus Thread notifications; Space opens Off; Ctrl+K opens command palette; Escape closes it; press Space. Reload Settings and repeat with Ctrl+P, then Escape twice and Space. Check focus returns to the trigger and the select reopens.

Scenario: Command palette returns keyboard interaction to a closed select trigger

Proven: the scenario fails on base 2b7b085254 and passes on head 29182665fa.

Base 2b7b085254 Head 29182665fa
Result ❌ failed
ASSERTION_FAILED: expected [false,false,false,false] to equal [true,true,true,true]
✅ passed
commands select open Base 2b7b085254: commands select open Head 29182665fa: commands select open
commands palette open Base 2b7b085254: commands palette open Head 29182665fa: commands palette open
commands space after close Base 2b7b085254: commands space after close Head 29182665fa: commands space after close
files select open Base 2b7b085254: files select open Head 29182665fa: files select open
files palette open Base 2b7b085254: files palette open Head 29182665fa: files palette open
files space after close Base 2b7b085254: files space after close Head 29182665fa: files space after close
failure Base 2b7b085254: failure
Before recording After recording
Base video Head video

Scenario source

Environment: Chromium web client, 1280×800, light theme, fresh isolated synthetic state on both commits. Base lost trigger focus and Space did nothing for both shortcuts; head restored trigger focus and Space reopened the select.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Dec 1, 2026
@juliusmarminge
juliusmarminge merged commit cf475c4 into pingdotgg:main Dec 1, 2026
56 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Dec 1, 2026
imetn added a commit to imetn/t4code that referenced this pull request Dec 2, 2026
Surgically ports 62 upstream Web UI fixes from pingdotgg/t3code
(772e3d4..1e6e7d7) into apps/web and scripts/scenarios while
preserving all 31 locked T4 customizations, T4 branding, and
t4-overrides.css.

Also restores React Compiler compilation for Sidebar by moving the
default new Set(...) parameter inside settleLaunchGroup into the
function body so switching threads produces 0 unaffected row re-renders.

Ported (62 commits):
- 1a08049 (pingdotgg#46481): right-panel launcher keys blocked while context menu open
- 6bdd718 (pingdotgg#46489): Enter restores highlighted stashed prompt (scenario e2e; web code already absorbed)
- 347f551 (pingdotgg#46490): Escape closes open context menu before layer beneath it
- afa3003 (pingdotgg#46487): workflows page uses width of wide window
- a2ba869 (pingdotgg#46485): keep joined emoji whole in screen-reader announcements
- a8ee725 (pingdotgg#46493): holding stash shortcut keeps prompt saved (scenario e2e; web code already absorbed)
- 5048c80 (pingdotgg#46499): Mod+S moves edited queued reply to prompt stash
- 179e6c3 (pingdotgg#46506): holding stash delete shortcut removes one prompt (scenario e2e; web code already absorbed)
- c101437 (pingdotgg#44079): fold PR diff whose header was clicked
- 9b27e5a (pingdotgg#46562): second Mod+T keeps right-panel Add menu shortcuts working
- 62cf1fe (pingdotgg#46592): wait for dialog focus before opening context menu over it
- fda1c30 (pingdotgg#46579): resting on issue row prefetches detail
- 28f0c93 (pingdotgg#46593): slash-command description tooltip closes when modal opens
- 789784b (pingdotgg#46603): keep selected tab in Workflows links
- 2bc37d9 (pingdotgg#46597): / and Mod+F in Settings ignore open context menu
- b21923b (pingdotgg#46640): effort shortcut closes nested Permissions menu in model picker
- a5a39fa (pingdotgg#46641): inline thread details card grows with interface font size
- 36983d6 (pingdotgg#46644): workflow runs open in resizable right panel
- 2ad902f (pingdotgg#46691): Mod+F on PRs page ignores open menu
- 97d727c (pingdotgg#46699): Link pull request dialog closes when leaving thread
- 7a9d213 (pingdotgg#46729): refuse saving edit to deleted project script action
- bdda9ce (pingdotgg#46745): settling open delegated task opens next thread
- 3763606 (pingdotgg#46760): command menu description tooltip closes on composer focus loss
- 00eae4b (pingdotgg#46764): reopen workflow run on first click
- 19094fd (pingdotgg#46765): boring sidebar folder rows offer snooze again
- dec756c (pingdotgg#46766): reopen last workflow run after hiding panel
- 33ce571 (pingdotgg#46777): keep workflow runs open behind tab menus
- a989ee8 (pingdotgg#46779): restore focus after closing workflow run
- 5c42b2e (pingdotgg#46786): reopen closed workflow run tabs
- caec30f (pingdotgg#46792): cancel tab drags when switching threads
- 27cf2cf (pingdotgg#46794): disable empty panel shortcuts as it closes
- d65936e (pingdotgg#46791): reveal all side panel tabs when they fit
- a9daa0b (pingdotgg#46781): right-panel shortcuts ignore presses while menu/dialog open
- 35b6c5f (pingdotgg#46801): dismissing PR checkout toast cancels handoff
- e9da1b0 (pingdotgg#46818): boring sidebar folder row actions keep height and clicks
- 9feac49 (pingdotgg#46855): long PR search preserves grapheme clusters
- acef160 (pingdotgg#46849): find shared voice dictionary by Japanese label
- 19da14d (pingdotgg#46796): scrolled right panel tabs no longer block chat titlebar drag
- 506bc36 (pingdotgg#46853): close guest share and handoff dialogs when leaving thread
- b4fd7ba (pingdotgg#46879): let Escape and app shortcuts pass through terminal font preview
- f5689ae (pingdotgg#46835): long history load errors wrap without timeline horizontal overflow
- 6b64b0c (pingdotgg#46890): focus command dialog popup when search input disabled
- 70c9da7 (pingdotgg#46900): focus PR Author/Labels filter search inputs on keyboard open
- 891bf1a (pingdotgg#46924): late slash results no longer open tooltip after focus leaves
- 80f0f8a (pingdotgg#46930): copying failed message keeps its images
- e9ca942 (pingdotgg#46659): show workflow question kinds only in filter
- aa8c7c7 (pingdotgg#46941): queued message moves to stash only once removed
- 3ea13b6 (pingdotgg#46940): editing answer while image prepares cancels held submit
- a143526 (pingdotgg#46970): pasting copied file over reattach marker no longer reports failure
- b33c330 (pingdotgg#47011): stub addComposerFilesToDraft with new return shape in test
- a0fb9d1 (pingdotgg#46974): Issues Labels/Assignee filters focus search on keyboard open
- cb525f4 (pingdotgg#47029): clicking anywhere on terminal or panel tab activates it
- 498a3b6 (pingdotgg#47022): syncing messages line no longer shifts whole chat
- e903c85 (pingdotgg#47046): pasted messages with thread link keep picture
- 6a13142 (pingdotgg#47013): limit style invalidation during right-panel resize
- cd8961e (pingdotgg#47078): pasting copied file no longer takes preparing screenshot slot
- 8d0fb4b (pingdotgg#47100): stop showing previous Usage period as loading after failure
- 515b8c9 (pingdotgg#47114): Tab from Permissions menu keeps focus inside model picker
- a681dd5 (pingdotgg#47125): middle-clicking file link no longer opens broken tab
- bbde8dc (pingdotgg#44842): use plus icon for project new-thread buttons
- 59af88f (pingdotgg#47105): switching threads no longer re-renders unaffected sidebar rows
- 1e6e7d7 (pingdotgg#47080): Reopen Closed Tab skips workflow runs removed from history

Already absorbed in HEAD (3 commits):
- 20a0e5f (pingdotgg#46927), a684090 (pingdotgg#47026), c557dab (pingdotgg#47076)

Skipped cleanly (3 commits):
- 70224ca (pingdotgg#46712): depends on unported ui/open-popups.tsx (pingdotgg#45341)
- cf475c4 (pingdotgg#47034): depends on unported ui/open-popups.tsx (pingdotgg#45341)
- be3cc6c (pingdotgg#47145): depends on unported fitsWithAllowance/workGroupOverflowAllowance in TimelineWorkGroupRows.tsx
imetn added a commit to imetn/t4code that referenced this pull request Dec 2, 2026
- M1: match inflected T3 brand forms (e.g. Swedish genitive 'T3 Codes') in
  scripts/sync-t4-i18n.ts and scripts/check-t4-branding.ts (+ tests), and
  restore 'T4 Codes' in sv.json (web + desktop).
- M2: check v11SimpleCarryIndex before upstream direct using three-way
  divergence rules in scripts/sync-t4-i18n.ts (+ tests), and restore all 19
  T4-curated zh translations (incl. {action}(回车), {host}令牌, {provider}令牌,
  and 子智能体正在运行) plus curated web de/sv variable overrides.
- m1: add GitHub HTTPS -> SSH fallback sentence to docs/user/source-control.md (pingdotgg#47239).
- m2: port pingdotgg#47034 (cf475c4) command palette popup trigger focus return + browser test.
- N3: port apps/web/src/i18n/runtime.test.ts covering browser languagechange.
- N1: update .t4-upstream-sync.json history count (30 PRs) and notes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants