Skip to content

Commit a303fcc

Browse files
committed
fix(ChatInput): prevent navigation on container drop and forward file drops to onDropFiles\n\n- Add container-level onDragOver/onDrop with preventDefault to avoid browser navigation\n- Forward file drops anywhere in ChatInput container to existing onDropFiles handler\n- Normalize onDropFiles to accept DragEvent<HTMLElement> so it can be reused by container and textarea\n- Keep textarea-level handlers; container now manages isDragging for full area
1 parent 83ce745 commit a303fcc

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

vibes.diy/pkg/app/components/ChatInput.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const ChatInput = forwardRef<ChatInputRef, ChatInputProps>(
114114
);
115115

116116
const onDropFiles = useCallback(
117-
async (e: React.DragEvent<HTMLTextAreaElement>) => {
117+
async (e: React.DragEvent<HTMLElement>) => {
118118
e.preventDefault();
119119
e.stopPropagation();
120120
setIsDragging(false);
@@ -127,7 +127,32 @@ const ChatInput = forwardRef<ChatInputRef, ChatInputProps>(
127127
);
128128

129129
return (
130-
<div ref={containerRef} className="px-4 py-2">
130+
<div
131+
ref={containerRef}
132+
className="px-4 py-2"
133+
onDragEnter={(e) => {
134+
e.preventDefault();
135+
setIsDragging(true);
136+
}}
137+
onDragOver={(e) => {
138+
// Prevent default to avoid the browser opening the file
139+
e.preventDefault();
140+
setIsDragging(true);
141+
}}
142+
onDragLeave={(e) => {
143+
e.preventDefault();
144+
setIsDragging(false);
145+
}}
146+
onDrop={(e) => {
147+
// Prevent navigation and route valid file drops to the shared handler
148+
e.preventDefault();
149+
e.stopPropagation();
150+
setIsDragging(false);
151+
if (e.dataTransfer?.files?.length) {
152+
void onDropFiles(e);
153+
}
154+
}}
155+
>
131156
<div className="space-y-2">
132157
{/* Attached images preview */}
133158
{Array.isArray(chatState.attachedImages) &&

0 commit comments

Comments
 (0)