Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
fix(drop-container): clear input value on change (#924)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
emyarod and kodiakhq[bot] authored Feb 3, 2022
1 parent 8323b6b commit fe78124
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/file-uploader/drop-container.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2020, 2021
* Copyright IBM Corp. 2020, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -45,7 +45,7 @@ class BXFileDropContainer extends HostListenerMixin(LitElement) {
*/
private _handleChange(event: Event | DragEvent) {
const addedFiles = this._getFiles(event);
const { eventChange } = this.constructor as typeof BXFileDropContainer;
const { eventChange, selectorInput } = this.constructor as typeof BXFileDropContainer;
this.dispatchEvent(
new CustomEvent(eventChange, {
bubbles: true,
Expand All @@ -55,6 +55,11 @@ class BXFileDropContainer extends HostListenerMixin(LitElement) {
},
})
);

const fileInput = this?.shadowRoot?.querySelector(selectorInput);
if (fileInput) {
(fileInput as HTMLInputElement).value = ''; // carbon-web-components#904
}
}

/**
Expand Down Expand Up @@ -161,6 +166,13 @@ class BXFileDropContainer extends HostListenerMixin(LitElement) {
return `${prefix}-file-drop-container-changed`;
}

/**
* A selector that will return the file `<input>`.
*/
static get selectorInput() {
return `.${prefix}--file-input`;
}

static styles = styles;
}

Expand Down

0 comments on commit fe78124

Please sign in to comment.