Skip to content

Commit

Permalink
fix selected file representation after reselect
Browse files Browse the repository at this point in the history
  • Loading branch information
k0va1 committed Apr 16, 2024
1 parent b6c0d55 commit abc94a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/polaris_view_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
29 changes: 29 additions & 0 deletions test/system/dropzone_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit abc94a8

Please sign in to comment.