From 55da3bf77087b3a75bb70de2035f849f5687e48f Mon Sep 17 00:00:00 2001 From: tjtanjin Date: Tue, 21 May 2024 01:22:11 +0800 Subject: [PATCH] fix: Fix an issue where users cannot enter new line in chat input --- src/components/ChatBotBody/ChatBotBody.css | 1 + src/components/ChatBotInput/ChatBotInput.tsx | 7 ++++++- src/services/BotOptionsService.tsx | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/ChatBotBody/ChatBotBody.css b/src/components/ChatBotBody/ChatBotBody.css index 84837bad..913ecf4d 100644 --- a/src/components/ChatBotBody/ChatBotBody.css +++ b/src/components/ChatBotBody/ChatBotBody.css @@ -52,6 +52,7 @@ font-size: 15px; overflow-wrap: anywhere; overflow: hidden; + white-space: pre-wrap; } .rcb-bot-message { diff --git a/src/components/ChatBotInput/ChatBotInput.tsx b/src/components/ChatBotInput/ChatBotInput.tsx index b89b1418..ea64dd58 100644 --- a/src/components/ChatBotInput/ChatBotInput.tsx +++ b/src/components/ChatBotInput/ChatBotInput.tsx @@ -123,7 +123,12 @@ const ChatBotInput = ({ */ const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "Enter") { - event.preventDefault(); + if (event.shiftKey) { + if (!botOptions.chatInput?.allowNewline) { + event.preventDefault(); + } + return; + } handleSubmit(event); } }; diff --git a/src/services/BotOptionsService.tsx b/src/services/BotOptionsService.tsx index a6b6fb9c..41b13b3a 100644 --- a/src/services/BotOptionsService.tsx +++ b/src/services/BotOptionsService.tsx @@ -79,6 +79,7 @@ const defaultOptions = { }, chatInput: { disabled: false, + allowNewline: false, enabledPlaceholderText: "Type your message...", disabledPlaceholderText: "", showCharacterCount: false,