whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.11k stars 2.67k forks source link

Should `<input type=file>` fire a change event when the user chooses the same file twice? #10724

Open josepharhar opened 1 week ago

josepharhar commented 1 week ago

What is the issue with the HTML Standard?

Safari and Chrome don't fire a second change event when the user chooses the same file, but firefox does. The spec just says this:

If the element is mutable, the user agent should allow the user to change the files on the list in other ways also, e.g., adding or removing files by drag-and-drop. When the user does so, the user agent must update the file selection for the element.

Should this behavior be interoperable? Should the spec say anything about this?

I'm guessing it isn't possible to write a WPT for this.

Context: https://issues.chromium.org/issues/40219625

Kaiido commented 5 days ago

There is a note in show the picker:

Similarly, it's up to the user agent whether re-selecting the same files counts as were previously selected counts as a dismissal, or as a change of selection.

So here Safari & Chromium chose cancel, and Firefox chose input, but authors should be able to handle any such cases the way they want by listening to both events.

One thing to note though, is that Chromium seems to only look at the file name. So if you select a file, remove it from disk and create a new, different file, with the same name as the first one, then Chromium will still not fire an event, that looks like a bug.