Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upuseSearchField `ref` type is incorrect #1017
Open
Labels
Comments
|
Thanks! Looks like it's always been an intersection but union appears to be be more appropriate |
RafalFilipek
linked a pull request that will
close
this issue
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


The types in
useSearchFieldfrom@react-aria/searchfieldat 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 typeHTMLInputElement & HTMLTextAreaElementbut it should probably beHTMLInputElement | HTMLTextAreaElementto 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);)The type should accept an
HTMLInputElementor andHTMLTextAreaElement, not the intersection of the two types.update the type here to be the union of the two, not the intersection.
@react-aria/searchfield@3.1.0Context
This should be an easy first issue for someone looking to contribute.
Workaround
Just cast to any like
useSearchField(props, state, ref as any)