Added input component to dom and added event listener instead of setting onChange

This commit is contained in:
Lucas Oliveira 2024-06-10 16:50:54 -03:00
commit 5f19ce9298

View file

@ -48,12 +48,12 @@ export default function InputFileComponent({
const handleButtonClick = (): void => {
// Create a file input element
const input = document.createElement("input");
document.body.appendChild(input);
input.type = "file";
input.accept = fileTypes?.join(",");
input.style.display = "none"; // Hidden from view
input.multiple = false; // Allow only one file selection
input.onchange = (event: Event): void => {
const onChangeFile = (event: Event): void => {
setLoading(true);
// Get the selected file
@ -90,6 +90,8 @@ export default function InputFileComponent({
}
};
input.addEventListener("change", onChangeFile);
// Trigger the file selection dialog
input.click();
};