[feat] FileInput ref should expose a reset prop to clear its value #958
Labels
type: breaking
This introduces breaking changes and will require a major version increase
type: feature
New feature or request
Does your feature request relate to a specific USWDS component?
The FileInput
What USWDS Version is this feature present in?
This is not related to a USWDS feature.
Is your feature request related to a problem? Please describe.
The
FileInput
exposes aninputRef
prop in order to allow users access to the underlyinginput
element. However, the file input element is unique in that itsvalue
cannot be set programmatically. This means that simply exposing a ref to theinput
element is not enough to allow a library user to reset the files selected by this input, which might be desirable if the user were implementing an async upload handler and wants to avoid rendering files in the FileInput component once they've been uploaded.Describe the solution you'd like
We should be able to use React's ref forwarding alongside the useImperativeHandle hook to customize the ref that is returned by
FileInput
and expose a method to parent components that can be called to reset the file state to an empty array.Additional context
We may want to start adopting this pattern for form control components that are more complex than a single
input
element (such as the ComboBox & DatePicker) and might also warrant exposing additional methods through a ref. This issue should help us get more understanding around this pattern, the use cases it fulfills, and how to move forward to ensure our form controls are highly adaptable for a variety of use cases.This issue depends on #900 and will likely result in a major version update.
The text was updated successfully, but these errors were encountered: