Ben Borgers

Disabling file uploads with the Trix editor

May 3, 2020

Basecamp's Trix text editor lets people upload their own files into the text they're writing, but maybe you don't want to deal with file uploads at the moment.

To disable file uploads, first remove the "file" button (it looks like a paperclip) using CSS:

trix-toolbar [data-trix-button-group="file-tools"] {
  display: none;
}

This removes the button, but it doesn't stop people from dragging files in. For that, add this javascript that ignores file uploads whenever one is attempted:

document.addEventListener("trix-file-accept", event => {
  event.preventDefault()
})

More blog posts

Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iā€™m working on!

Twitter ↗ RSS feed ↗