Skip to content

Commit 5eb1035

Browse files
authored
fix(cdk/drag-drop): error when cloning file input with value (#20793)
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.
1 parent f854196 commit 5eb1035

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/cdk/drag-drop/clone-node.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ let cloneUniqueId = 0;
5050
/** Transfers the data of one input element to another. */
5151
function transferInputData(source: Element & {value: string},
5252
clone: Element & {value: string; name: string; type: string}) {
53-
clone.value = source.value;
53+
// Browsers throw an error when assigning the value of a file input programmatically.
54+
if (clone.type !== 'file') {
55+
clone.value = source.value;
56+
}
57+
5458
// Radio button `name` attributes must be unique for radio button groups
5559
// otherwise original radio buttons can lose their checked state
5660
// once the clone is inserted in the DOM.

0 commit comments

Comments
 (0)