Replies: 2 comments
-
Hey @tjosepo! Thanks for the proposal, it's very interesting. I am not sure I am willing to re-open this part of the code thought 😅 Basically it's a shared collection API used by every components using items, it's not a standalone implementation for the Select component. Composition should work. Maybe something has broken for the Select. Pretty sure at some point I had written Chromatic tests testing composition for every component using the collection API. Maybe something broke for the Select component and I removed the feature at some point since nobody seemed to have use this in like 2 years 😆 Anyway, you can find a working Chromatic test showcasing composition with an There's also always the option to embed your own logic. In the following test case it's simply mapping an array but pretty much everything is possible as the clients has full control on the rendered items. |
Beta Was this translation helpful? Give feedback.
-
i do agree that this is a better way of doing this. Moved into a discussion for now, since realistically we won’t be tackling this short term |
Beta Was this translation helpful? Give feedback.
-
Description
Currently, the Autocomplete, Listbox, Menu and Select components all represent items using the Item component.
A typical usage of the Item component looks like this:
Problems
The Item component presents a few limitations:
Fragments
The following code would not work, because React only considers that Select has 3 children: "earth", "jupiter", and "React.Fragment".
It's not possible to get the key from within the fragment.
Turning the fragment into an array of elements, doesn't work either.
When doing so, React adds a prefix to
element.key
which breaks the euristics used in Orbit to parse the keys.Lack of composition
Similar to the issues with fragments, Items cannot be grouped into components, as the children would become the component, instead of the Items within the component.
Not recommended by React
React's Special Props Warning specifically warns against using keys in app logic.
Keys are used as reconciling hints by React, and there is no guaranteed that implementations details will remain the same in the future.
Proposal: Option component
I propose the creation of a new Option component which solves all the previously mentionned issues.
How?
Using Context and useLayoutEffect, basically. I wrote a gist for the implementation.
Usage:
Issues with this proposal
If you can think of anything else, feedback is welcome and appreciated! 😄
Beta Was this translation helpful? Give feedback.
All reactions