Limit accept attachment file types, fix missing id and make Trix compatible with modals #1135
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
While integrating Trix, I found a conflict if I wanted to attach files and Trix was inside a modal, as discussed in issue #1039. Additionally, I needed to restrict the attached files to only images. During debugging, I also noticed that the input element was missing an ID, a problem previously reported in issue #1088 by @chadrschroeder. To address this, I monkey-patched it in my implementation and decided to create this pull request.
Changes
trix-editor
instead of doing it at the end of the bodyfileInputId
based on Restore Missing fileInputId Property and Add acceptedFileTypes Property #1089To solve 2 and 3 I had to use the
editorController
instance as an argument of thepickFiles
function instead of just using the callback.Let me know if you consider that not all the changes are needed or if there are any issues with the code.
How it works
Trix will still accept all file types as an attachment by default, but now a
trix-attachment-accept
attribute is available, which takes a comma-separated list of allowed file extensions or MIME types.