Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileInput - unable to use as controlled component; unable to reset input state externally #7197

Open
nateq314 opened this issue Apr 11, 2024 · 0 comments

Comments

@nateq314
Copy link
Contributor

nateq314 commented Apr 11, 2024

Expected Behavior

  • Would expect that I can provide a FileList or similar object as a value prop to control the files externally.
  • Would expect that even if not controlled, if I manually reset the input's files object to an empty FileList (using a ref, getElementById, etc.), then the component would reset to its initial state. This is highly problematic for UIs that use a modal or some other means of completing the file manipulation (upload or whatever). The modal will have a "Close" button and it is normal and expected that when the modal closes, the input should reset.

Actual Behavior

State is apparently managed internally, and the only way to reset the input is to click the "X" button. Actually it is possible to set the input's FileList object to empty manually (using the method shown in code below), but doing so leaves FileInput in an inconsistent state, as the text label still shows the name of the previously selected file, and examining internal state shows that the File object itself (referencing the previous file) is still present.

URL, screen shot, or Codepen exhibiting the issue

Screen Shot 2024-04-11 at 11 36 54 AM

Steps to Reproduce

(self explanatory, also see code snippet)

Your Environment

@nateq314 nateq314 changed the title FileInput - cannot currently be used as a * controlled * component FileInput - unable to use as controlled component; unable to reset input state externally Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant