fix: focus input when page refresh (#2814)
* fix: focus input when page refresh * fix: increase to 100ms
This commit is contained in:
@@ -12,15 +12,22 @@ function SearchInput({ defaultValue, ...rest }: Props) {
|
||||
const theme = useTheme();
|
||||
const inputRef = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
const focusInput = React.useCallback(() => {
|
||||
inputRef.current?.focus();
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
// ensure that focus is placed at end of input
|
||||
const len = (defaultValue || "").length;
|
||||
inputRef.current?.setSelectionRange(len, len);
|
||||
}, [defaultValue]);
|
||||
const timeoutId = setTimeout(() => {
|
||||
focusInput();
|
||||
}, 100); // arbitrary number
|
||||
|
||||
const focusInput = React.useCallback(() => {
|
||||
inputRef.current?.focus();
|
||||
}, []);
|
||||
return () => {
|
||||
clearTimeout(timeoutId);
|
||||
};
|
||||
}, [defaultValue, focusInput]);
|
||||
|
||||
return (
|
||||
<Wrapper align="center">
|
||||
|
||||
Reference in New Issue
Block a user