Skip to content

Commit 0e35b58

Browse files
committed
fix(FR-791): Add drop container to sender (#3469)
resolves #3468 (FR-791) # Fix ChatInput component's drop container reference This PR fixes an issue in the `ChatInput` component by correctly passing the `dropContainerRef` to both the parent `Flex` component and the `ChatSender` component. Previously, the reference was created but not properly attached to the container element, which could affect file drop functionality. **Changes:** - Renamed `cardRef` to `dropContainerRef` for better semantic clarity - Added the ref to the parent `Flex` component - Passed the same ref to the `ChatSender` component
1 parent 0d6da1f commit 0e35b58

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

react/src/components/Chat/ChatCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ const ChatCard: React.FC<ChatCardProps> = ({
165165
styles: { chatCard: chatCardStyle, alert: alertStyle, ...chatCardStyles },
166166
} = useStyles();
167167
const formRef = useRef<FormInstance>(null);
168+
const dropContainerRef = useRef<HTMLDivElement>(null);
168169
const [fetchKey, updateFetchKey] = useUpdatableState('first');
169170
const [startTime, setStartTime] = useState<number | null>(null);
170171

@@ -265,6 +266,7 @@ const ChatCard: React.FC<ChatCardProps> = ({
265266
setMessages={setMessages}
266267
/>
267268
}
269+
ref={dropContainerRef}
268270
>
269271
<CustomModelForm
270272
modelId={modelId}
@@ -299,6 +301,7 @@ const ChatCard: React.FC<ChatCardProps> = ({
299301
stop={stop}
300302
append={append}
301303
isLoading={isLoading}
304+
dropContainerRef={dropContainerRef}
302305
/>
303306
</Card>
304307
);

react/src/components/Chat/ChatInput.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { createDataTransferFiles } from '../../helper';
22
import Flex from '../Flex';
3-
import ChatSender, { AttachmentChangeInfo } from './ChatSender';
3+
import ChatSender, {
4+
AttachmentChangeInfo,
5+
ChatAttachmentsProps,
6+
} from './ChatSender';
47
import { CreateMessage, Message } from '@ai-sdk/react';
58
import type { AttachmentsProps } from '@ant-design/x';
69
import { ChatRequestOptions } from 'ai';
@@ -21,7 +24,7 @@ interface ChatRequest {
2124
fetchOnClient?: boolean;
2225
}
2326

24-
interface ChatInputProps extends ChatRequest {
27+
interface ChatInputProps extends ChatRequest, ChatAttachmentsProps {
2528
sync: boolean;
2629
input: string;
2730
setInput: (input: string) => void;
@@ -40,6 +43,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
4043
stop,
4144
append,
4245
isLoading,
46+
dropContainerRef,
4347
}) => {
4448
const { token } = theme.useToken();
4549

@@ -50,7 +54,6 @@ const ChatInput: React.FC<ChatInputProps> = ({
5054

5155
const [isOpenAttachments, setIsOpenAttachments] = useState(false);
5256
const [files, setFiles] = useState<AttachmentsProps['items']>([]);
53-
const cardRef = useRef<HTMLDivElement>(null);
5457

5558
const [synchronizedMessage, setSynchronizedMessage] = useAtom(
5659
synchronizedMessageState,
@@ -202,7 +205,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
202205
value={input}
203206
items={files}
204207
openAttachment={isOpenAttachments}
205-
dropContainerRef={cardRef}
208+
dropContainerRef={dropContainerRef}
206209
loading={isLoading}
207210
onInputChange={handleInputChange}
208211
onInputSubmit={handleInputSubmit}

react/src/components/Chat/ChatSender.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { isEmpty } from 'lodash';
1111
import { useEffect, useRef } from 'react';
1212
import { useTranslation } from 'react-i18next';
1313

14-
interface ChageAttachmentsProps extends AttachmentsProps {
14+
export interface ChatAttachmentsProps {
1515
dropContainerRef: React.RefObject<HTMLElement | null>;
1616
}
1717

18-
const ChatAttachments: React.FC<ChageAttachmentsProps> = ({
18+
const ChatAttachments: React.FC<ChatAttachmentsProps & AttachmentsProps> = ({
1919
items,
2020
onChange,
2121
dropContainerRef,
@@ -51,12 +51,13 @@ export type AttachmentChangeInfo = Parameters<
5151
NonNullable<UploadProps['onChange']>
5252
>[0];
5353

54-
interface ChatSenderProps extends Omit<SenderProps, 'onChange'> {
54+
interface ChatSenderProps
55+
extends Omit<SenderProps, 'onChange'>,
56+
ChatAttachmentsProps {
5557
loading?: boolean;
5658
autoFocus?: boolean;
5759
items?: Attachment[];
5860
openAttachment?: boolean;
59-
dropContainerRef: React.RefObject<HTMLDivElement | null>;
6061
onInputChange?: (value: string) => void;
6162
onInputSubmit?: () => void;
6263
onInputCancel?: () => void;

0 commit comments

Comments
 (0)