Using Attachments in Comments allows you to create an even more engaging in-app experience, meaning your users can easily communicate by sharing document attachments in comments.
In today’s digital landscape, users expect more than just text-based
communication. The ability to share files, images, and other media with
colleagues is essential for a complete collaborative experience, and without it,
users will fall back to email, Slack, or other file-sharing tools.
Our React components in Comments and Text Editor
now allow you to attach files to comments, and this is enabled by default. Users
can upload files using the file picker, or by dragging/pasting files into the
composer.
All files types are supported, and our Pro plan allows individual
files up to 50MB in size. When clicking on attachments, each type of file uses
its default browser behavior—usually opening media in a new tab, or downloading
the file.
It’s possible to customize this behavior using the onAttachmentClick prop on
Thread. For example
below, we’re cancelling the default behaviour, and instead calling custom
methods to download the file and display a toast notification.
<Threadkey={thread.id}thread={thread}onAttachmentClick={({ attachment, url }, e)=>{ e.preventDefault(); // Custom behavior on click__downloadFile__(url);__toast__(`${attachment.name} has been downloaded`);}}/>
Attachments are optional and can also be disabled, make sure to read our
upgrade guide to learn more.
Along with our default components, we’ve also made it possible to build
attachments using new primitive components. For example, below we’re showing a
completely custom Comments setup with attachments.
To render each attached file in the composer,
useComposer provides
you with information to render. For example, here’s how to list each attachment
in a composer.