From f39c642801e7c32b37c401ff80e3039d13d13ef3 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Thu, 29 Apr 2021 11:10:53 -0400 Subject: [PATCH] chat: refocus and reset state on submit, allow enter linebreaks on mobile --- .../views/apps/chat/components/ChatInput.tsx | 2 ++ .../views/apps/chat/components/chat-editor.js | 17 ++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx index fe83a0aef..ad5f255a8 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatInput.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatInput.tsx @@ -74,6 +74,8 @@ class ChatInput extends Component { } else { onSubmit(tokenizeMessage(text)); } + this.chatEditor.current.editor.focus(); + this.setState({ currentInput: '' }); } uploadSuccess(url: string) { diff --git a/pkg/interface/src/views/apps/chat/components/chat-editor.js b/pkg/interface/src/views/apps/chat/components/chat-editor.js index 3fbf94226..df87abe5e 100644 --- a/pkg/interface/src/views/apps/chat/components/chat-editor.js +++ b/pkg/interface/src/views/apps/chat/components/chat-editor.js @@ -240,17 +240,12 @@ export default class ChatEditor extends Component { rows="1" style={{ width: '100%', background: 'transparent', color: 'currentColor' }} placeholder={inCodeMode ? "Code..." : "Message..."} - onChange={event => { - this.messageChange(null, null, event.target.value); - }} - onKeyDown={event => { - if (event.key === 'Enter') { - event.preventDefault(); - this.submit(); - } else { - this.messageChange(null, null, event.target.value); - } - }} + onChange={event => + this.messageChange(null, null, event.target.value) + } + onKeyDown={event => + this.messageChange(null, null, event.target.value) + } ref={input => { if (!input) return; this.editor = inputProxy(input);