Skip to content

fix(desktop): restore focus to new workspace modal after alt-tab#3276

Closed
kkjcheng wants to merge 2 commits intosuperset-sh:mainfrom
kkjcheng:fix/desktop-workspace-modal-focus-loss
Closed

fix(desktop): restore focus to new workspace modal after alt-tab#3276
kkjcheng wants to merge 2 commits intosuperset-sh:mainfrom
kkjcheng:fix/desktop-workspace-modal-focus-loss

Conversation

@kkjcheng
Copy link
Copy Markdown
Contributor

@kkjcheng kkjcheng commented Apr 8, 2026

Summary

  • The new workspace modal Dialog used non-modal mode (modal={false} default), so Radix UI did not trap focus
  • When alt-tabbing away and back, focus landed on the window body instead of returning to the modal
  • Enabled modal on both NewWorkspaceModal and DashboardNewWorkspaceModal Dialog variants to activate Radix's built-in focus trap

Test plan

  • Open the new workspace modal
  • Alt-tab to another application, then alt-tab back
  • Verify focus returns to the modal (e.g. typing should land in the prompt input, not behind the modal)
  • Verify Escape still closes the modal
  • Verify clicking the overlay still closes the modal

Summary by cubic

Restores focus and keeps the New Workspace dialogs open after alt-tab by enabling modal on the Dialog and preventing focus-outside dismiss in DashboardNewWorkspaceModal.

  • Bug Fixes
    • After alt-tab, focus returns to the modal and it stays open (no unintended dismiss).
    • Escape and overlay click still close the modal.

Written for commit bdf35f2. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Workspace creation dialogs now prevent interaction with other interface elements while open, ensuring true modal behavior.
    • Dialog content now blocks focus from leaving the modal, improving accessibility and preventing accidental focus loss during workspace creation.

The Dialog defaulted to non-modal mode, so Radix did not trap focus.
When alt-tabbing away and back, focus landed on the window body instead
of returning to the modal. Enabling `modal` on both workspace dialog
variants activates Radix's built-in focus trap.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7ff55958-eddd-4e93-a592-2c1aa7e0839a

📥 Commits

Reviewing files that changed from the base of the PR and between a8d490f and bdf35f2.

📒 Files selected for processing (1)
  • apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceModal.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceModal.tsx

📝 Walkthrough

Walkthrough

Enabled the modal prop on Dialogs in two workspace modal components and added a onFocusOutside={(e) => e.preventDefault()} handler to the Dashboard modal; existing open state and close handlers remain unchanged.

Changes

Cohort / File(s) Summary
NewWorkspaceModal
apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx
Added modal prop to Dialog to make it modal; open={isOpen} and existing close handler unchanged.
DashboardNewWorkspaceModal
apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceModal.tsx
Added modal prop to Dialog and onFocusOutside={(e) => e.preventDefault()} on DialogContent to prevent focus-leave dismissal; open and close behavior preserved.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰
I hopped in code and set it tight,
Two dialogs now hold focus right.
No stray clicks to send them roaming,
Modal doors keep pathways homing.
A tiny tweak — the UX glowing.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: enabling modal behavior to restore focus to the new workspace modal after alt-tab.
Description check ✅ Passed The description includes a clear summary, detailed test plan, related technical context, and follows most template requirements with comprehensive information about the fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 8, 2026

Greptile Summary

This PR enables modal mode on both NewWorkspaceModal and DashboardNewWorkspaceModal Dialog components so that Radix UI activates its built-in focus trap, restoring focus to the modal after an alt-tab.

Key changes:

  • NewWorkspaceModal: adds modal prop to <Dialog> — correctly paired with the existing onFocusOutside={(e) => e.preventDefault()} on DialogContent.
  • DashboardNewWorkspaceModal: adds modal prop to <Dialog> — but is missing onFocusOutside={(e) => e.preventDefault()}, meaning Radix's default dismiss-on-focus-outside will fire and close the modal when the user alt-tabs away. The fix is incomplete for this variant.

Confidence Score: 3/5

Not safe to merge as-is — DashboardNewWorkspaceModal will close on alt-tab instead of preserving focus, making the fix worse than the original bug for that variant.

The fix is correct and complete for NewWorkspaceModal, but DashboardNewWorkspaceModal is missing the onFocusOutside prevention that is essential to the stated goal. Without it, modal=true causes Radix to dismiss the dialog on alt-tab, which is a regression. One targeted one-liner fix is needed before merge.

apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceModal.tsx — needs onFocusOutside={(e) => e.preventDefault()} on DialogContent

Vulnerabilities

No security concerns identified. Changes are limited to dialog focus-management props with no data handling or auth implications.

Important Files Changed

Filename Overview
apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx Adds modal prop to Dialog to activate Radix focus trap; already has onFocusOutside prevention to keep the dialog open on alt-tab — this file is correct.
apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceModal.tsx Adds modal prop to Dialog but is missing onFocusOutside={(e) => e.preventDefault()}, so alt-tabbing away will close the modal entirely instead of preserving and restoring focus.

Sequence Diagram

sequenceDiagram
    participant User
    participant OS
    participant RadixDialog as Radix Dialog (modal=true)
    participant DialogContent

    User->>RadixDialog: Opens modal
    RadixDialog->>DialogContent: Traps focus inside FocusScope

    User->>OS: Alt-tab away
    OS-->>RadixDialog: Window loses focus → onFocusOutside fires

    alt NewWorkspaceModal (has onFocusOutside preventDefault)
        DialogContent-->>RadixDialog: e.preventDefault() — suppress close
        RadixDialog-->>DialogContent: Modal stays open
        User->>OS: Alt-tab back
        OS-->>RadixDialog: Window regains focus
        RadixDialog-->>DialogContent: Focus restored to modal ✅
    else DashboardNewWorkspaceModal (missing preventDefault)
        DialogContent-->>RadixDialog: Default: onOpenChange(false)
        RadixDialog-->>DialogContent: Modal closes ❌
        User->>OS: Alt-tab back
        OS-->>User: Modal is gone — fix incomplete
    end
Loading

Comments Outside Diff (1)

  1. apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceModal.tsx, line 30-33 (link)

    P1 Missing onFocusOutside prevention — modal will close on alt-tab

    DashboardNewWorkspaceModal sets modal (good, fixes focus trap on return), but it is missing the onFocusOutside={(e) => e.preventDefault()} handler that NewWorkspaceModal already carries.

    With modal={true}, Radix UI's default behavior for onFocusOutside is to call onOpenChange(false) — i.e., close the dialog — when focus leaves the window scope. This means that when the user alt-tabs away, DashboardNewWorkspaceModal will close entirely rather than keeping the modal open and restoring focus on return. This is arguably worse than the original bug.

    NewWorkspaceModal avoids this by suppressing the default:

    onFocusOutside={(e) => e.preventDefault()}

    The same handler should be added to DashboardNewWorkspaceModal's DialogContent:

Reviews (1): Last reviewed commit: "fix(desktop): restore focus to new works..." | Re-trigger Greptile

Add onFocusOutside prevention to match NewWorkspaceModal — without it,
modal mode causes Radix to dismiss the dialog when focus moves outside
on alt-tab, which is a regression.
Kitenite added a commit that referenced this pull request Apr 13, 2026
Applies the same fix as #3276 to both v1 (NewWorkspaceModal) and v2
(DashboardNewWorkspaceModal) Dialogs so alt-tabbing back restores
focus to the modal.
Kitenite added a commit that referenced this pull request Apr 13, 2026
…3392)

* fix(desktop): enable modal focus trap on v1 + v2 workspace dialogs

Applies the same fix as #3276 to both v1 (NewWorkspaceModal) and v2
(DashboardNewWorkspaceModal) Dialogs so alt-tabbing back restores
focus to the modal.

* Lint
@Kitenite
Copy link
Copy Markdown
Collaborator

Superseded by #3392, which applies this same focus-trap fix to both the v1 (NewWorkspaceModal) and v2 (DashboardNewWorkspaceModal) dialogs on the sync-ws-v1-v2 branch. Credit retained — the fix is yours, just carried forward onto the branch where both variants currently live. Thanks @kkjcheng!

@Kitenite Kitenite closed this Apr 13, 2026
MocA-Love pushed a commit to MocA-Love/superset that referenced this pull request Apr 13, 2026
…uperset-sh#3392)

* fix(desktop): enable modal focus trap on v1 + v2 workspace dialogs

Applies the same fix as superset-sh#3276 to both v1 (NewWorkspaceModal) and v2
(DashboardNewWorkspaceModal) Dialogs so alt-tabbing back restores
focus to the modal.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants