-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
[Autocomplete] Add index to renderOption's AutocompleteRenderOptionState #35578
[Autocomplete] Add index to renderOption's AutocompleteRenderOptionState #35578
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't option.id
work for you? You can even get the option's index with data-option-index
attribute (props['data-option-index']
).
@ZeeshanTamboli (Initially misunderstood your prop option, updated response) I would have to look at that, but definitely could work for grabbing the index if it is on the props object from |
@ZeeshanTamboli - I reviewed your suggestion about That being said I do think explicitly exposing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CowDotDev Your reasoning sounds good to me. It's fine from my side. The code looks good. However, I would still like other team member to take the final decision. @michaldudak Can you take a look?
Yeah, I agree that getting data from a DOM attribute doesn't feel great. Let's include the |
The purpose of this PR is to simply expose the index that
renderListOption
intakes, coming from theAutcompleteListbox
groupedOptions.map
rendering. This allows a developer to have an easy, and more performant, way to reference the current option's index inside therenderOption
callback method.The use-case that brought up this issue was during my attempts at adding virtualization to our Autocomplete components. Our autocompletes that need virtualization may already be using
renderOptions
, or they may simply be usinggetOptionLabel
. Either way, in order to create a single "VirtualizedAutocomplete" wrapper that can accept varying render sources as well as support lists where the rendered options have varying heights we need to be able to reference the index of the option being rendered.Example Without this PR's Change - Inline Comments Denoting What Would Change
While my use-case is specific to Virtualization, and there are other ways to may be more performant to index all the options, I believe this addition is generic enough that other developers will find it useful and comes at no cost as the index was already being supplied to the method that calls
renderOption
.