Skip to content

fix(ui): Focus first text input by default#4134

Merged
TheodoreSpeaks merged 5 commits intostagingfrom
fix/user-input-focus
Apr 13, 2026
Merged

fix(ui): Focus first text input by default#4134
TheodoreSpeaks merged 5 commits intostagingfrom
fix/user-input-focus

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

@TheodoreSpeaks TheodoreSpeaks commented Apr 13, 2026

Summary

Currently modals and modal tabs don't auto-focus on the first text input. This is annoying for the user.

Modified both emcn modal and modal tabs to by default auto-focus on the first available user input.
Also added focusing logic for the copilot sidebar and mothership tasks to auto focus.
Fixes #(issue)

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Checked copilot, mothership, all settings modals, deploy description modal, etc to ensure focusing is set on the first user input.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 13, 2026 11:25pm

Request Review

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator Author

@BugBot review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 13, 2026

PR Summary

Medium Risk
Changes default focus behavior for shared ModalContent/SModalContent and tabbed modals, which may affect keyboard flow across many dialogs despite being limited to UI focus management.

Overview
Improves UX around text entry by making emcn modals auto-focus the first visible text input/textarea (caret placed at end) instead of the close button, and by focusing the first text field when ModalTabs switches panels.

Removes scattered autoFocus props from multiple modals and replaces one-off focusing in IntegrationsManager with the new helper. Also tightens chat focus behavior by re-focusing the textarea after resource/file drops in UserInput and when switching the workflow panel to the copilot tab.

Reviewed by Cursor Bugbot for commit 9261f15. Bugbot is set up for automated code reviews on this repo. Configure here.

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator Author

@BugBot review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9261f15. Configure here.

@TheodoreSpeaks TheodoreSpeaks marked this pull request as ready for review April 13, 2026 23:31
@TheodoreSpeaks TheodoreSpeaks changed the title Fix/user input focus (wip) fix(ui): Focus first text input by default Apr 13, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 13, 2026

Greptile Summary

This PR centralises modal auto-focus by introducing a shared focusFirstTextInputIn / focusFirstTextInput utility and wiring it as the default onOpenAutoFocus handler on both ModalContent and SModalContent. It also upgrades ModalTabs to re-focus the first text input on tab switch, adds copilot-panel and user-input focus on mount, and removes the now-redundant autoFocus attributes scattered across individual modals.

All remaining findings are P2 style/documentation items that do not block merge.

Confidence Score: 5/5

Safe to merge — all findings are non-blocking P2 style and documentation issues.

The core auto-focus utility is well-written (visibility guard, caret placement, setSelectionRange error guard). The ModalTabs RAF timing correctly lets React commit before querying data-state. Removed autoFocus props are safely replaced by the centralised handler. The three P2 comments are about hook ordering, a misleading JSDoc, and an undocumented isInitialView behaviour change — none affect correctness.

apps/sim/app/workspace/[workspaceId]/settings/components/integrations/integrations-manager.tsx (hook ordering), apps/sim/components/emcn/components/modal/modal.tsx (ModalTabsContent JSDoc)

Important Files Changed

Filename Overview
apps/sim/components/emcn/components/modal/auto-focus.ts New utility: well-implemented focusFirstTextInputIn/focusFirstTextInput helpers with correct visibility check, caret-at-end placement, and setSelectionRange error guard.
apps/sim/components/emcn/components/modal/modal.tsx Adds default onOpenAutoFocus (first text input) to ModalContent; wraps ModalTabs as a forwardRef to focus first text input on tab change — JSDoc on ModalTabsContent is slightly misleading since focus lives in ModalTabs.
apps/sim/components/emcn/components/s-modal/s-modal.tsx Mirrors ModalContent change: SModalContent now accepts and defaults to focusFirstTextInput for onOpenAutoFocus.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Removes isInitialView guard from focus effect (now always focuses on mount) and adds post-drop focus restoration; the behavior change is intentional but undocumented.
apps/sim/app/workspace/[workspaceId]/settings/components/integrations/integrations-manager.tsx Adds useEffect/ref to focus step-2 modal inputs; useState for serviceSearch is incorrectly placed after the useEffect, violating hook ordering convention.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx Adds useEffect to focus copilot textarea when activeTab switches to 'copilot'; uses existing data-tab-content='copilot' attribute which is already defined in the panel, so the query is safe.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Modal / SModal opens] --> B[onOpenAutoFocus fires on DialogContent]
    B --> C[focusFirstTextInput]
    C --> D{Find first visible\ntext input in dialog}
    D -- found --> E[focus + caret at end]
    D -- not found --> F[Radix default focus runs]

    G[ModalTabs tab changes] --> H[handleValueChange]
    H --> I[requestAnimationFrame]
    I --> J{Find active tabpanel\ndata-state=active}
    J -- found --> K[focusFirstTextInputIn panel]
    J -- not found --> L[no-op]

    M[UserInput mounts] --> N[requestAnimationFrame on mount]
    N --> O[textareaRef.current?.focus]

    P[Panel activeTab → copilot] --> Q[setTimeout 0ms]
    Q --> R[document.querySelector textarea]
    R --> S[textarea?.focus]
Loading

Comments Outside Diff (1)

  1. apps/sim/components/emcn/components/modal/modal.tsx, line 373-386 (link)

    P2 Misleading JSDoc on ModalTabsContent

    The doc says "focus moves to the first visible text-entry input inside it" but ModalTabsContent itself is a thin passthrough — it adds only pb-2.5. The actual focus logic lives in ModalTabs.handleValueChange. The comment should either be moved to ModalTabs, or reworded to describe the observable behavior without implying ModalTabsContent is responsible for it.

Reviews (1): Last reviewed commit: "Auto-focus mothership task chats" | Re-trigger Greptile

@TheodoreSpeaks TheodoreSpeaks merged commit c0db9de into staging Apr 13, 2026
11 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the fix/user-input-focus branch April 13, 2026 23:40
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.

1 participant