From 8a7166d9d10d12bb082a6a2f07f53e94d9bf04d5 Mon Sep 17 00:00:00 2001 From: Robert Kozik Date: Thu, 15 Feb 2024 09:19:30 +0100 Subject: [PATCH] Introduce autoFocus functionality for web (#175) --- src/MarkdownTextInput.web.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/MarkdownTextInput.web.tsx b/src/MarkdownTextInput.web.tsx index 9872079a..429785b9 100644 --- a/src/MarkdownTextInput.web.tsx +++ b/src/MarkdownTextInput.web.tsx @@ -150,6 +150,7 @@ const MarkdownTextInput = React.forwardRef( spellCheck, style = {}, value, + autoFocus = false, }, ref, ) => { @@ -500,6 +501,14 @@ const MarkdownTextInput = React.forwardRef( }; }, []); + 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