Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/react/src/views/ChatInput/ChatInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,40 @@ const ChatInput = ({ scrollToBottom }) => {
break;
}
};
const handlePasteImages = (e) => {
const { items } = e.clipboardData;
Array.from(items).forEach((item) => {
if (item.type.indexOf('image') !== -1) {
const imageBlob = item.getAsFile();
const file = new File(
[imageBlob],
`Clipboard- ${new Date().toLocaleString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
})}.png`,
{
type: imageBlob.type,
lastModified: Date.now(),
}
);

toggle();
setData(file);
e.preventDefault();
}
});
};

useEffect(() => {
const inputElement = messageRef.current;
inputElement.addEventListener('paste', handlePasteImages);
return () => {
inputElement.removeEventListener('paste', handlePasteImages);
};
});

return (
<Box className={`ec-chat-input ${classNames}`} style={styleOverrides}>
Expand Down
Loading