Skip to content

Commit d6ae691

Browse files
authored
feat: 添加setInputArea接口 (#319)
1 parent d6ab517 commit d6ae691

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/components/ProChat/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export interface ProChatInstance<T = Record<string, any>> {
8484
message: Partial<ChatMessage<T>>,
8585
userType: 'assistant' | 'user',
8686
) => ChatMessage<T>;
87+
88+
setInputAreaValue: (value: string) => void;
8789
}
8890

8991
export type ProChatChatReference<T = Record<string, any>> = MutableRefObject<
@@ -529,6 +531,7 @@ export function ProChat<
529531
inputAreaRender={inputAreaRender}
530532
inputRender={inputRender}
531533
inputAreaProps={inputAreaProps}
534+
chatRef={chatRef}
532535
actionStyle={styles?.chatInputAction}
533536
sendAreaStyle={styles?.chatSendAreaStyle}
534537
areaStyle={styles?.chatInputArea}

src/components/ProChatInputArea/index.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useRefFunction } from '@/hooks/useRefFunction';
2-
import { ChatMessage } from '@/index';
2+
import { ChatMessage, ProChatChatReference } from '@/index';
33
import { ProChatLocale } from '@/locale';
44
import { SendOutlined } from '@ant-design/icons';
55
import { Button, ButtonProps, ConfigProvider, Flex } from 'antd';
66
import cx from 'classnames';
7-
import { useContext, useMemo, useRef, useState } from 'react';
7+
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
88
import AnimationItem from '../Animation';
99
import { ProChatActionBar, ProChatActionBarProps } from './ActionBar';
1010
import { MentionsTextArea, MentionsTextAreaProps } from './AutoCompleteTextArea';
@@ -75,6 +75,8 @@ export type ChatInputAreaProps = {
7575
* Locale configuration for the ProChat component.
7676
*/
7777
locale?: ProChatLocale;
78+
79+
chatRef?: ProChatChatReference;
7880
/**
7981
* Callback function to clear the message input.
8082
*/
@@ -133,6 +135,7 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
133135
onMessageSend,
134136
actionStyle,
135137
locale,
138+
chatRef,
136139
mentionRequest,
137140
actionsRender,
138141
} = props || {};
@@ -144,7 +147,12 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
144147
const prefixClass = getPrefixCls('pro-chat-input-area');
145148

146149
const { wrapSSR, hashId } = useStyle(prefixClass);
147-
150+
useEffect(() => {
151+
if (!chatRef || !chatRef.current) return;
152+
chatRef.current.setInputAreaValue = (value) => {
153+
setMessage(value);
154+
};
155+
}, [chatRef]);
148156
const send = useRefFunction(async () => {
149157
if (onSend && message) {
150158
const success = await onSend(message);

0 commit comments

Comments
 (0)