Skip to content

Commit

Permalink
fix(UI): prevent frequent triggering of input method on mobile device…
Browse files Browse the repository at this point in the history
…s when focusing on searchbar
  • Loading branch information
rockbenben committed Jan 1, 2025
1 parent 309b4af commit 6092a1e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/pages/_components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,14 @@ function SearchBar({ setShowUserPrompts = (value: boolean) => {}, setShowUserFav
const searchRef = useRef<Input>(null);
const [value, setValue] = useState<string | null>(null);

const isMobile = useCallback(() => {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}, []);

useEffect(() => {
setValue(readSearchName(location.search));
if (searchRef.current?.input) {
// 只在非移动设备上自动获取焦点
if (!isMobile() && searchRef.current?.input) {
searchRef.current.input.focus();
}
}, [location]);
Expand Down Expand Up @@ -220,6 +225,7 @@ function SearchBar({ setShowUserPrompts = (value: boolean) => {}, setShowUserFav
onChange={handleInput}
onPressEnter={handleSearch}
allowClear
autoFocus={!isMobile()}
suffix={<Button icon={<SearchOutlined />} onClick={handleSearch} type="primary" />}
/>
</div>
Expand Down

0 comments on commit 6092a1e

Please sign in to comment.