Scroll to top on search

This commit is contained in:
Dan Abramov
2023-12-23 19:38:22 +00:00
parent 4a3a45dfdf
commit 0f2f890fee
+11
View File
@@ -463,6 +463,7 @@ export function SearchScreenMobile(
setDrawerOpen(true) setDrawerOpen(true)
}, [track, setDrawerOpen]) }, [track, setDrawerOpen])
const onPressCancelSearch = React.useCallback(() => { const onPressCancelSearch = React.useCallback(() => {
scrollToTopWeb()
textInput.current?.blur() textInput.current?.blur()
setQuery('') setQuery('')
setShowAutocompleteResults(false) setShowAutocompleteResults(false)
@@ -470,11 +471,13 @@ export function SearchScreenMobile(
clearTimeout(searchDebounceTimeout.current) clearTimeout(searchDebounceTimeout.current)
}, [textInput]) }, [textInput])
const onPressClearQuery = React.useCallback(() => { const onPressClearQuery = React.useCallback(() => {
scrollToTopWeb()
setQuery('') setQuery('')
setShowAutocompleteResults(false) setShowAutocompleteResults(false)
}, [setQuery]) }, [setQuery])
const onChangeText = React.useCallback( const onChangeText = React.useCallback(
async (text: string) => { async (text: string) => {
scrollToTopWeb()
setQuery(text) setQuery(text)
if (text.length > 0) { if (text.length > 0) {
@@ -503,10 +506,12 @@ export function SearchScreenMobile(
[setQuery, search, setSearchResults], [setQuery, search, setSearchResults],
) )
const onSubmit = React.useCallback(() => { const onSubmit = React.useCallback(() => {
scrollToTopWeb()
setShowAutocompleteResults(false) setShowAutocompleteResults(false)
}, [setShowAutocompleteResults]) }, [setShowAutocompleteResults])
const onSoftReset = React.useCallback(() => { const onSoftReset = React.useCallback(() => {
scrollToTopWeb()
onPressCancelSearch() onPressCancelSearch()
}, [onPressCancelSearch]) }, [onPressCancelSearch])
@@ -620,6 +625,12 @@ export function SearchScreenMobile(
) )
} }
function scrollToTopWeb() {
if (isWeb) {
window.scrollTo(0, 0)
}
}
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
// @ts-ignore web only // @ts-ignore web only