-
Notifications
You must be signed in to change notification settings - Fork 29
NTP: Move focus to input when switching Omnibar tabs #1823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NTP: Move focus to input when switching Omnibar tabs #1823
Conversation
✅ Deploy Preview for content-scope-scripts ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Temporary Branch UpdateThe temporary branch has been updated with the latest changes. Below are the details:
Please use the above install command to update to the latest version. |
[Beta] Generated file diffTime updated: Tue, 15 Jul 2025 10:30:46 GMT Integration
File has changed Windows
File has changed Apple
File has changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@noisysocks I tried this, one problem now (sorry!) is that the input steals focus from the address bar, perhaps the rule needs to be, auto-focus when there's some input.
Please go back to native/design folks to get some clarity on this one, I'm not confident on the expectations
b537cbd
to
9245641
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: AutoFocus State Persistence Causes Input Issues
The autoFocus
state is set to true
when switching tabs but is never reset to false
. This leads to two unintended behaviors:
- Inputs are auto-focused after form submissions (due to component remounting via
resetKey
), even when the user didn't switch tabs. - Subsequent tab switches fail to auto-focus inputs because the
autoFocus
prop's value remainstrue
, preventing the focus effect from re-triggering.
special-pages/pages/new-tab/app/omnibar/components/Omnibar.js#L28-L60
content-scope-scripts/special-pages/pages/new-tab/app/omnibar/components/Omnibar.js
Lines 28 to 60 in 9245641
const [resetKey, setResetKey] = useState(0); | |
const [autoFocus, setAutoFocus] = useState(false); | |
const { openSuggestion, submitSearch, submitChat } = useContext(OmnibarContext); | |
const resetForm = () => { | |
setQuery(''); | |
setResetKey((prev) => prev + 1); | |
}; | |
/** @type {(params: {suggestion: Suggestion, target: OpenTarget}) => void} */ | |
const handleOpenSuggestion = (params) => { | |
openSuggestion(params); | |
resetForm(); | |
}; | |
/** @type {(params: {term: string, target: OpenTarget}) => void} */ | |
const handleSubmitSearch = (params) => { | |
submitSearch(params); | |
resetForm(); | |
}; | |
/** @type {(params: {chat: string, target: OpenTarget}) => void} */ | |
const handleSubmitChat = (params) => { | |
submitChat(params); | |
resetForm(); | |
}; | |
/** @type {(mode: OmnibarConfig['mode']) => void} */ | |
const handleChangeMode = (nextMode) => { | |
setAutoFocus(true); | |
setMode(nextMode); | |
}; |
Was this report helpful? Give feedback by reacting with 👍 or 👎
Asana Task/Github Issue: https://app.asana.com/1/137249556945/project/1209121419454298/task/1210785568574517?focus=true
Description
Moves focus to the input or textarea when switching to the Search or Duck.ai tabs.
Testing Steps
Checklist
Please tick all that apply: