Skip to content

Commit

Permalink
add autofocus handler
Browse files Browse the repository at this point in the history
  • Loading branch information
severinlandolt committed Nov 7, 2023
1 parent b63263e commit 444d8eb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/input-elements/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const BaseInput = React.forwardRef<HTMLInputElement, BaseInputProps>((props, ref
className,
onChange,
onValueChange,
autoFocus,
...other
} = props;
const [isFocused, setIsFocused] = useState(false);
Expand All @@ -57,6 +58,14 @@ const BaseInput = React.forwardRef<HTMLInputElement, BaseInputProps>((props, ref
setIsFocused(isFocused);
};

React.useEffect(() => {
// If the autoFocus prop is true, then set the isFocused state to true
if (autoFocus && inputRef.current) {
inputRef.current.focus();
setIsFocused(true);
}
}, [autoFocus]);

return (
<>
<div
Expand Down

0 comments on commit 444d8eb

Please sign in to comment.