Wrapper Component for Item
#4270
-
I have a custom Item component for my Listbox that doesn't do much besides add some props to the type definition that get used when we render an It's something like this: type CustomListboxProps = {
label: string
}
export type ListboxOptionProps = React.ComponentPropsWithoutRef<Item> & CustomListboxProps
export const ListboxOption = (props: ListboxOptionProps) => null;
Object.assign(ListboxOption, Item) This works pretty well, but I have another component where, for backwards compatibility, I need to accept a I did try to wrap the ListboxOption.getCollectionNode = function* getCollectionNode(props: ListboxOptionProps & { key?: string | number }, context: unknown) {
const { value, key, ...rest } = props
const newProps = {
...rest,
key: value ?? key,
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
yield* (Item as unknown as any).getCollectionNode(newProps, context)
} Is there any way to wrap an item or map props to accept a different prop name for key? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For now this isn't really supported, though you started having the right idea of how you could implement it with getCollectionNode. However, often you can make a component that you put inside In the future wrapping Item will be supported, however. See this section of our recent React Aria Components RFC for more details on how that will work. |
Beta Was this translation helpful? Give feedback.
For now this isn't really supported, though you started having the right idea of how you could implement it with getCollectionNode. However, often you can make a component that you put inside
<Item>
rather than wrapping Item itself. For example,<Item><FancyListBoxOption {...someProps} /></Item>
.In the future wrapping Item will be supported, however. See this section of our recent React Aria Components RFC for more details on how that will work.