The type for ListBoxItem (and possibly others) changed from having props intersectioned with RefAttributes<HTMLDivElement> (technically this is wrong too since the component could be an HTMLAnchorElement) to RefAttributes<T>
This means that if a ref prop is added it now requires type casting to satisfy TS, but is incorrect according to what the ref actually gets bound: <ListBoxItem ref={ref as ForwardedRef<T>} />, when ref is really attached to the DOM element a | div
This change seems to have occurred around the time of the switch over to @react-aria/collections, types are more correct in "react-aria-components": "1.2.1"
๐ค Expected Behavior?
Exported type for const ListBoxItem should be same type as the inner function ListBoxItem
Need to check the types for other components wrapped with createLeafComponent
๐ฏ Current Behavior
RefAttributes receives generic type T instead of the expected DOM element type
๐ Possible Solution
Correct return type of createLeafComponent to maintain ref type
Potentially also update ListBoxItem type to have union of HTMLAnchorElement | HTMLDivElement
๐ฆ Context
No response
๐ฅ๏ธ Steps to Reproduce
The code sandbox environment isn't in TS, so not possible to show there
Provide a general summary of the issue here
The type for
ListBoxItem
(and possibly others) changed from having props intersectioned withRefAttributes<HTMLDivElement>
(technically this is wrong too since the component could be anHTMLAnchorElement
) toRefAttributes<T>
https://github.com/adobe/react-spectrum/blob/98e21e19d50b4bf5c9114e17a75cca4c11254db0/packages/%40react-aria/collections/src/CollectionBuilder.tsx#L161
https://github.com/adobe/react-spectrum/blob/98e21e19d50b4bf5c9114e17a75cca4c11254db0/packages/react-aria-components/src/ListBox.tsx#L318
This means that if a ref prop is added it now requires type casting to satisfy TS, but is incorrect according to what the ref actually gets bound:
<ListBoxItem ref={ref as ForwardedRef<T>} />
, whenref
is really attached to the DOM elementa | div
This change seems to have occurred around the time of the switch over to
@react-aria/collections
, types are more correct in "react-aria-components": "1.2.1"๐ค Expected Behavior?
Exported type for
const ListBoxItem
should be same type as the innerfunction ListBoxItem
Need to check the types for other components wrapped with
createLeafComponent
๐ฏ Current Behavior
RefAttributes
receives generic typeT
instead of the expected DOM element type๐ Possible Solution
Correct return type of
createLeafComponent
to maintain ref typePotentially also update
ListBoxItem
type to have union ofHTMLAnchorElement | HTMLDivElement
๐ฆ Context
No response
๐ฅ๏ธ Steps to Reproduce
The code sandbox environment isn't in TS, so not possible to show there
Version
"@react-aria/collections": "3.0.0-alpha.3", "react-aria-components": "1.3.1"
What browsers are you seeing the problem on?
Other
If other, please specify.
Typescript
What operating system are you using?
Mac & Windows
๐งข Your Company/Team
No response
๐ท Tracking Issue
No response