Skip to content

[Dropzone] Upload same file empty the drop zone, chrome only #2552

Open
@nforgeot-norsys

Description

@nforgeot-norsys

When you upload the same file, Chrome do not trigger change event. Firefox do. I think Chrome have the correct behavior this time.

This behavior introduced an issue in the UX dropzone. In chrome, when you upload the same file, the dropzone is emptied.

bug_dropzone_same_file.webm

Solution : Listen the drop event and show the drop zone if a input value is set.

What do you think of this solution ? Tested ok in Chrome and Firefox.

in https://github.com/symfony/ux/blob/v2.22.1/src/Dropzone/assets/dist/controller.js

    initialize() {
        // ...
        this.onDrop = this.onDrop.bind(this);
    }

    connect() {
        // ...
        this.element.addEventListener('drop', this.onDrop);
    }

    disconnect() {        // ...
        this.element.removeEventListener('drop', this.onDrop);
    }

    onDrop() {
        if (this.inputTarget.value === '') {
            return;
        }

        this.inputTarget.style.display = 'none';
        this.placeholderTarget.style.display = 'none';
        this.previewTarget.style.display = 'flex';
    }

If it's ok for you, I can try to do the PR ;)

Activity

smnandre

smnandre commented on Feb 7, 2025

@smnandre
Member

Hey @nforgeot-norsys ! Not 100% sur to get how the problem occurs (i probably missed something)

I had the impression that either onchage was triggerd, and current file was replaced, onchange was not triggered, so current file stayed there...

Do you have any other script involved here ?

nforgeot-norsys

nforgeot-norsys commented on Feb 10, 2025

@nforgeot-norsys
Author

Hey @smnandre

current file was replaced, onchange was not triggered, so current file stayed there...

Yes that it. It's Chrome behaviour. But Firefox trigger every time.

No I don't have other script involved in this behavior. I have made a little test in a sandbox to demonstrate that https://jsfiddle.net/a6jng31u/ .

linked a pull request that will close this issue on May 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @smnandre@carsonbot@nforgeot-norsys

      Issue actions

        [Dropzone] Upload same file empty the drop zone, chrome only · Issue #2552 · symfony/ux