Added input component to dom and added event listener instead of setting onChange
This commit is contained in:
parent
1e1b40be65
commit
5f19ce9298
1 changed files with 4 additions and 2 deletions
|
|
@ -48,12 +48,12 @@ export default function InputFileComponent({
|
||||||
const handleButtonClick = (): void => {
|
const handleButtonClick = (): void => {
|
||||||
// Create a file input element
|
// Create a file input element
|
||||||
const input = document.createElement("input");
|
const input = document.createElement("input");
|
||||||
|
document.body.appendChild(input);
|
||||||
input.type = "file";
|
input.type = "file";
|
||||||
input.accept = fileTypes?.join(",");
|
input.accept = fileTypes?.join(",");
|
||||||
input.style.display = "none"; // Hidden from view
|
input.style.display = "none"; // Hidden from view
|
||||||
input.multiple = false; // Allow only one file selection
|
input.multiple = false; // Allow only one file selection
|
||||||
|
const onChangeFile = (event: Event): void => {
|
||||||
input.onchange = (event: Event): void => {
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// Get the selected file
|
// Get the selected file
|
||||||
|
|
@ -90,6 +90,8 @@ export default function InputFileComponent({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
input.addEventListener("change", onChangeFile);
|
||||||
|
|
||||||
// Trigger the file selection dialog
|
// Trigger the file selection dialog
|
||||||
input.click();
|
input.click();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue