Skip to content

Commit

Permalink
Introduce autoFocus functionality for web (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertKozik authored Feb 15, 2024
1 parent eba5620 commit 8a7166d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
spellCheck,
style = {},
value,
autoFocus = false,
},
ref,
) => {
Expand Down Expand Up @@ -500,6 +501,14 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
};
}, []);

useEffect(() => {
// focus the input on mount if autoFocus is set
if (!(divRef.current && autoFocus)) {
return;
}
divRef.current.focus();
}, []);

return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
Expand Down

0 comments on commit 8a7166d

Please sign in to comment.