1
1
import { useRefFunction } from '@/hooks/useRefFunction' ;
2
- import { ChatMessage } from '@/index' ;
2
+ import { ChatMessage , ProChatChatReference } from '@/index' ;
3
3
import { ProChatLocale } from '@/locale' ;
4
4
import { SendOutlined } from '@ant-design/icons' ;
5
5
import { Button , ButtonProps , ConfigProvider , Flex } from 'antd' ;
6
6
import cx from 'classnames' ;
7
- import { useContext , useMemo , useRef , useState } from 'react' ;
7
+ import { useContext , useEffect , useMemo , useRef , useState } from 'react' ;
8
8
import AnimationItem from '../Animation' ;
9
9
import { ProChatActionBar , ProChatActionBarProps } from './ActionBar' ;
10
10
import { MentionsTextArea , MentionsTextAreaProps } from './AutoCompleteTextArea' ;
@@ -75,6 +75,8 @@ export type ChatInputAreaProps = {
75
75
* Locale configuration for the ProChat component.
76
76
*/
77
77
locale ?: ProChatLocale ;
78
+
79
+ chatRef ?: ProChatChatReference ;
78
80
/**
79
81
* Callback function to clear the message input.
80
82
*/
@@ -133,6 +135,7 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
133
135
onMessageSend,
134
136
actionStyle,
135
137
locale,
138
+ chatRef,
136
139
mentionRequest,
137
140
actionsRender,
138
141
} = props || { } ;
@@ -144,7 +147,12 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
144
147
const prefixClass = getPrefixCls ( 'pro-chat-input-area' ) ;
145
148
146
149
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 ] ) ;
148
156
const send = useRefFunction ( async ( ) => {
149
157
if ( onSend && message ) {
150
158
const success = await onSend ( message ) ;
0 commit comments