Skip to content

Commit

Permalink
🐛 fix: disable Enter when loading (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
gin-lsl authored Aug 2, 2024
1 parent 9a29e1a commit 79df7fb
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/ProChat/components/InputArea/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -133,7 +133,7 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
* @property {function} onPressEnter - 按下回车键时的回调函数
*/

const defaultAutoCompleteTextAreaProps = {
const defaultAutoCompleteTextAreaProps: GetProps<typeof AutoCompleteTextArea> = {
placeholder: placeholder || localeObject.placeholder,
...inputAreaProps,
className: cx(styles.input, inputAreaProps?.className, `${prefixClass}-component`),
Expand All @@ -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();
}
}
},
};
Expand Down

0 comments on commit 79df7fb

Please sign in to comment.