Skip to content

Commit

Permalink
fix(cdk/drag-drop): error when cloning file input with value
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 angular#20783.
  • Loading branch information
crisbeto committed Oct 14, 2020
1 parent 5bac828 commit 5cea3a5
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 5cea3a5

Please sign in to comment.