From 91c895a7e3a58ea3c3ee69e43cf3db1791d64014 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 8 Apr 2019 11:26:58 +0300 Subject: Fix MessageInput tests --- vnext/src/components/MessageInput.js | 6 +- .../src/components/__tests__/MessageInput-test.js | 65 ++++++++++++++-------- 2 files changed, 48 insertions(+), 23 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/components/MessageInput.js b/vnext/src/components/MessageInput.js index bd80d1ea..32c32d8d 100644 --- a/vnext/src/components/MessageInput.js +++ b/vnext/src/components/MessageInput.js @@ -14,11 +14,14 @@ export default function MessageInput({ data, rows, children, onSend }) { let textareaRef = useRef(); let fileinput = useRef(); - useEffect(() => { + let updateFocus = () => { const isDesktop = window.matchMedia('(min-width: 62.5rem)'); if (isDesktop.matches) { textareaRef.current.focus(); } + }; + useEffect(() => { + updateFocus(); }, []); let handleCtrlEnter = (event) => { @@ -53,6 +56,7 @@ export default function MessageInput({ data, rows, children, onSend }) { formState.values.body = ''; textareaRef.current.value = ''; textareaRef.current.style.height = ''; + updateFocus(); }; return (