diff --git a/app/assets/javascripts/polaris_view_components.js b/app/assets/javascripts/polaris_view_components.js index e1475bd8..531637d1 100644 --- a/app/assets/javascripts/polaris_view_components.js +++ b/app/assets/javascripts/polaris_view_components.js @@ -451,8 +451,8 @@ class Dropzone extends Controller { onChange(e) { this.stopEvent(e); if (this.disabled) return; - this.clearFiles(); const fileList = getDataTransferFiles(e); + this.clearFiles(); const {files: files, acceptedFiles: acceptedFiles, rejectedFiles: rejectedFiles} = this.getValidatedFiles(fileList); this.dragTargets = []; this.files = files; diff --git a/app/assets/javascripts/polaris_view_components/dropzone_controller.js b/app/assets/javascripts/polaris_view_components/dropzone_controller.js index c9f66e95..c784a2ab 100644 --- a/app/assets/javascripts/polaris_view_components/dropzone_controller.js +++ b/app/assets/javascripts/polaris_view_components/dropzone_controller.js @@ -94,9 +94,9 @@ export default class extends Controller { this.stopEvent(e) if (this.disabled) return + const fileList = getDataTransferFiles(e) this.clearFiles() - const fileList = getDataTransferFiles(e) const { files, acceptedFiles, rejectedFiles } = this.getValidatedFiles(fileList) this.dragTargets = [] diff --git a/test/system/dropzone_component_test.rb b/test/system/dropzone_component_test.rb index d4cbd25b..f4d238c4 100644 --- a/test/system/dropzone_component_test.rb +++ b/test/system/dropzone_component_test.rb @@ -115,6 +115,35 @@ def test_multiple_direct_uploads assert_text "Attachments (2)" end + def test_reselect_file + with_preview("dropzone_component/with_file_upload") + + find(".Polaris-DropZone").drop(fixture_file("file.txt"), fixture_file("image.png")) + assert_selector ".Polaris-DropZone__Preview > .Polaris-LegacyStack > .Polaris-LegacyStack__Item", count: 2 + within ".Polaris-DropZone__Preview > .Polaris-LegacyStack" do + assert_selector ".Polaris-LegacyStack__Item:nth-child(1)" do + assert_text "file.txt" + assert_text "10 Bytes" + end + assert_selector ".Polaris-LegacyStack__Item:nth-child(2)" do + assert_text "image.png" + assert_text "11.37 KB" + end + end + + page.attach_file(fixture_file("image.png")) do + page.find(".Polaris-DropZone").click + end + + assert_selector ".Polaris-DropZone__Preview > .Polaris-LegacyStack > .Polaris-LegacyStack__Item", count: 1 + within ".Polaris-DropZone__Preview > .Polaris-LegacyStack" do + assert_selector ".Polaris-LegacyStack__Item:nth-child(1)" do + assert_text "image.png" + assert_text "11.37 KB" + end + end + end + def fixture_file(name) Rails.root.join("../test/fixtures/#{name}") end