From a8a53cc69134cd6b7f61512637b69527fa4c6f59 Mon Sep 17 00:00:00 2001 From: gin-lsl Date: Sat, 27 Jul 2024 15:17:15 +0800 Subject: [PATCH] :bug: fix: disable Enter when loading --- src/ProChat/components/InputArea/index.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ProChat/components/InputArea/index.tsx b/src/ProChat/components/InputArea/index.tsx index d7543e6..62dbde2 100644 --- a/src/ProChat/components/InputArea/index.tsx +++ b/src/ProChat/components/InputArea/index.tsx @@ -1,5 +1,5 @@ import { SendOutlined } from '@ant-design/icons'; -import { Button, ButtonProps, ConfigProvider } from 'antd'; +import { Button, ButtonProps, ConfigProvider, GetProps } from 'antd'; import { createStyles, cx } from 'antd-style'; import { ReactNode, useContext, useEffect, useMemo, useRef, useState } from 'react'; import { Flexbox } from 'react-layout-kit'; @@ -133,7 +133,7 @@ export const ChatInputArea = (props: ChatInputAreaProps) => { * @property {function} onPressEnter - 按下回车键时的回调函数 */ - const defaultAutoCompleteTextAreaProps = { + const defaultAutoCompleteTextAreaProps: GetProps = { placeholder: placeholder || localeObject.placeholder, ...inputAreaProps, className: cx(styles.input, inputAreaProps?.className, `${prefixClass}-component`), @@ -147,12 +147,18 @@ export const ChatInputArea = (props: ChatInputAreaProps) => { }, onCompositionEnd: (e) => { isChineseInput.current = false; - setMessage(e.target.value); + setMessage((e.target as HTMLTextAreaElement).value); }, onPressEnter: (e) => { - if (!isLoading && !e.shiftKey && !isChineseInput.current) { - e.preventDefault(); - send(); + if (isLoading) { + if (!e.shiftKey) { + e.preventDefault(); + } + } else { + if (!e.shiftKey && !isChineseInput.current) { + e.preventDefault(); + send(); + } } }, };