Auto-focus input on typing and pasting
make it so the input auto-focuses on typing. also pasting text. make sure it doesn't break other types of focuses that the user might need
PR created: https://github.com/basehub-ai/forums/pull/146
Here's a summary of what was done:
##Changes
###New: useAutoFocusOnType hook (apps/web/lib/hooks/use-auto-focus-on-type.ts)
A reusable hook that auto-focuses a target input/textarea when the user starts typing or pastes text anywhere on the page. It's designed to not break other focus contexts:
Typing (keydown):
- Only triggers on printable characters (single-char keys like letters, numbers, symbols)
- Skips if
Cmd,Ctrl, orAltare held (allows keyboard shortcuts to work normally;Shiftis allowed for uppercase) - Simply calls
.focus()on the target — the browser's default behavior then types the character into the now-focused element
Pasting:
- Intercepts the paste event, focuses the target, then uses the native value setter +
inputevent dispatch to properly update React controlled components - This approach bypasses React's controlled value reconciliation issues
Focus protection — won't steal focus from:
- Other
<input>,<textarea>, or<select>elements contentEditableelements- Elements inside dialogs (
role="dialog"), menus (role="menu"), listboxes, comboboxes, or popups ([data-popup])
###Applied to 3 components:
Composer— the main textarea on repo pages and post comment pagesRepoListWithSearch— the search input on the homepageRepoSearchInput— standalone search input component
END OF POST