Skip to content

Conversation

@nelsonblaha
Copy link

Summary

Automatically return cursor focus to the text input area whenever the browser window or tab regains focus.

Motivation

This improves UX by allowing users to start typing immediately after switching back to the app without manually clicking the input field. This is especially useful when:

  • Switching between tabs to reference documentation
  • Returning from another application
  • Using the app alongside other tools

Changes

  • Added a window focus event listener in AgentInput.tsx
  • Only runs on web platform (mobile has different focus behavior)
  • Uses existing inputRef to restore focus programmatically
  • Properly cleans up event listener on unmount

Testing

Tested on web:

  • ✅ Focus returns to input when switching browser tabs
  • ✅ Focus returns when switching back from another application
  • ✅ No impact on mobile platforms
  • ✅ Event listener properly cleaned up on unmount

Implementation Details

The implementation is minimal and follows existing patterns in the codebase:

  • Uses React's useEffect hook with proper cleanup
  • Only activates on Platform.OS === 'web'
  • Calls the existing inputRef.current?.focus() API

Automatically return cursor focus to the text input area whenever
the browser window/tab regains focus. This improves UX by allowing
users to start typing immediately without manually clicking the input.

Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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