Commit bbb616f5 authored by Charles Bachmeier's avatar Charles Bachmeier Committed by GitHub

feat: auto set cursor on searchbar opening (#4552)

* auto set cursor on searchbar opening

* comment update
Co-authored-by: default avatarCharlie <charlie@uniswap.org>
parent 35a429ea
...@@ -269,6 +269,7 @@ export const SearchBar = () => { ...@@ -269,6 +269,7 @@ export const SearchBar = () => {
const [searchValue, setSearchValue] = useState('') const [searchValue, setSearchValue] = useState('')
const debouncedSearchValue = useDebounce(searchValue, 300) const debouncedSearchValue = useDebounce(searchValue, 300)
const searchRef = useRef<HTMLDivElement>(null) const searchRef = useRef<HTMLDivElement>(null)
const inputRef = useRef<HTMLInputElement>(null)
const { pathname } = useLocation() const { pathname } = useLocation()
const phase1Flag = useNftFlag() const phase1Flag = useNftFlag()
const isMobile = useIsMobile() const isMobile = useIsMobile()
...@@ -321,6 +322,13 @@ export const SearchBar = () => { ...@@ -321,6 +322,13 @@ export const SearchBar = () => {
setSearchValue('') setSearchValue('')
}, [pathname]) }, [pathname])
// auto set cursor when searchbar is opened
useEffect(() => {
if (isOpen) {
inputRef.current?.focus()
}
}, [isOpen])
const placeholderText = phase1Flag === NftVariant.Enabled ? t`Search tokens and NFT collections` : t`Search tokens` const placeholderText = phase1Flag === NftVariant.Enabled ? t`Search tokens and NFT collections` : t`Search tokens`
return ( return (
...@@ -359,6 +367,7 @@ export const SearchBar = () => { ...@@ -359,6 +367,7 @@ export const SearchBar = () => {
}} }}
className={styles.searchBarInput} className={styles.searchBarInput}
value={searchValue} value={searchValue}
ref={inputRef}
/> />
</Row> </Row>
<Box display={{ sm: isOpen ? 'none' : 'flex', xl: 'none' }}> <Box display={{ sm: isOpen ? 'none' : 'flex', xl: 'none' }}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment