The Wayback Machine - http://web.archive.org/web/20200901154641/https://github.com/adobe/react-spectrum/issues/1017
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

useSearchField `ref` type is incorrect #1017

Open
shrugs opened this issue Aug 25, 2020 · 1 comment · May be fixed by #1027
Open

useSearchField `ref` type is incorrect #1017

shrugs opened this issue Aug 25, 2020 · 1 comment · May be fixed by #1027

Comments

@shrugs
Copy link

@shrugs shrugs commented Aug 25, 2020

🐛 Bug Report

The types in useSearchField from @react-aria/searchfield at https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/searchfield/src/useSearchField.ts#L40 says that the hook requires a ref to the type HTMLInputElement & HTMLTextAreaElement but it should probably be HTMLInputElement | HTMLTextAreaElement to allow the user to pass one or the other, instead of a type that is the intersection of both.

With the current types, the example at https://react-spectrum.adobe.com/react-aria/useSearchField.html is invalid.
(also worth noting that for typescript to be happy, the ref must be typed like so: const ref = useRef<HTMLInputElement>(null);)

🤔 Expected Behavior

The type should accept an HTMLInputElement or and HTMLTextAreaElement, not the intersection of the two types.

💁 Possible Solution

update the type here to be the union of the two, not the intersection.

🌍 Your Environment

Software Version(s)
react-spectrum @react-aria/searchfield@3.1.0

Context

This should be an easy first issue for someone looking to contribute.

Workaround

Just cast to any like useSearchField(props, state, ref as any)

@snowystinger
Copy link
Collaborator

@snowystinger snowystinger commented Aug 26, 2020

Thanks! Looks like it's always been an intersection but union appears to be be more appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.