Skip to content

Commit

Permalink
fix(cdk/drag-drop): error when cloning file input with value (#20793)
Browse files Browse the repository at this point in the history
When we clone the dragged element to generate its preview, we transfer the values of
inputs so that they look identical. The problem is that assigning the value of a `file` input
will throw an error so we have to skip it.

**Note:** does not include a unit test, because we can't set the of a test element programmatically.

Fixes #20783.

(cherry picked from commit 5eb1035)
  • Loading branch information
crisbeto authored and annieyw committed Oct 16, 2020
1 parent 77358cc commit ff5d09f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cdk/drag-drop/clone-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ let cloneUniqueId = 0;
/** Transfers the data of one input element to another. */
function transferInputData(source: Element & {value: string},
clone: Element & {value: string; name: string; type: string}) {
clone.value = source.value;
// Browsers throw an error when assigning the value of a file input programmatically.
if (clone.type !== 'file') {
clone.value = source.value;
}

// Radio button `name` attributes must be unique for radio button groups
// otherwise original radio buttons can lose their checked state
// once the clone is inserted in the DOM.
Expand Down

0 comments on commit ff5d09f

Please sign in to comment.