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 => {
|
||||
// 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();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue