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

[feat] FileInput ref should expose a reset prop to clear its value #958

Closed
suzubara opened this issue Feb 25, 2021 · 0 comments · Fixed by #1165
Closed

[feat] FileInput ref should expose a reset prop to clear its value #958

suzubara opened this issue Feb 25, 2021 · 0 comments · Fixed by #1165
Assignees
Labels
type: breaking This introduces breaking changes and will require a major version increase type: feature New feature or request

Comments

@suzubara
Copy link
Contributor

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 an inputRef prop in order to allow users access to the underlying input element. However, the file input element is unique in that its value cannot be set programmatically. This means that simply exposing a ref to the input 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.

@suzubara suzubara added the type: feature New feature or request label Feb 25, 2021
@haworku haworku added this to the v2 milestone Feb 26, 2021
@suzubara suzubara removed this from the v2 milestone Apr 12, 2021
@suzubara suzubara added the type: breaking This introduces breaking changes and will require a major version increase label Apr 12, 2021
@suzubara suzubara self-assigned this Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: breaking This introduces breaking changes and will require a major version increase type: feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants