basecamp / basecamp/trix

Clicking to Attach a File Deletes First Element on Page with ID of "undefined"

Open
#1,088 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
20k
Forks
1.1k
Avg merge
3d 12h
Merged PRs (30d)
13

Description

While overriding the `pickFiles` function, I noticed that there is no `fileInputId` property to provide a unique ID for the dynamically inserted file input element.

Back in Trix version 1, that existed [here](https://github.com/basecamp/trix/blob/1.3.1/src/trix/config/input.coffee#L21) and looked like:

```coffeescript
fileInputId: "trix-file-input-#{Date.now().toString(16)}"
```

The entire `pickFiles` function was removed [here](https://github.com/basecamp/trix/commit/40a8e33f6343971f1ef6d7c0b439925353c32424#diff-b6ecefb73ea0d1f0413e5c9ea055b434f75e7691e984abc475bbf79c9eb2e900). Then that function was added back without `fileInputId` [here](https://github.com/basecamp/trix/commit/2c6c48080c4844b9ba0b2feda171215c080ecb27#diff-2307591fa6d5a739a31c8198158d9d5f30fdec71af33029947e927bda0bff640).

This means that if for some strange reason you had another element on the page with an `id` of "undefined", clicking to add a file in Trix would remove that element.

Also, as a side question--would you be open to a pull request that adds a way to configure the `accept` property on the `pickFiles` input element? I need to restrict the types of files a user can select. I know I can check the file type in the `trix-file-accept` event and call `event.preventDefault()` there, but that happens after the user has already selected a file. It would be nice to be able to restrict the list of possible files while they are making the selection. (**Update:** I now see pull request https://github.com/basecamp/trix/pull/789 addresses this and has been open for over 3 years.)

##### Details

* Trix version: 2.0.5

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the current pickFiles entry point and compare it with the linked Trix 1 input configuration. Reproduce the case with another page element whose id is "undefined", then verify that choosing a file no longer removes it. The separate accept-attribute request is already addressed by the linked pull request and should be treated independently.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.