Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
josepharhar opened this issue Oct 25, 2024 · 3 comments

Comments

@josepharhar
Copy link
Contributor

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
Copy link
Member

Kaiido commented Oct 27, 2024

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.

@smaug----
Copy link

Seems like the behavior in Firefox is quite reasonable, and implementation doesn't need to keep track whether the file changed or not. The behavior also doesn't leak any information about some file changing or not.

@annevk
Copy link
Member

annevk commented Nov 4, 2024

Presumably you can tell whether a file changes by looking at <input>.files? There's even a requirement that it returns the same object until there's a change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants