Skip to content
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] Streamline Mapping Value to Options #44863

Closed
aress31 opened this issue Dec 26, 2024 · 7 comments
Closed

[Autocomplete] Streamline Mapping Value to Options #44863

aress31 opened this issue Dec 26, 2024 · 7 comments
Labels
component: autocomplete This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists

Comments

@aress31
Copy link

aress31 commented Dec 26, 2024

Summary

Currently, when using non-flattened options (e.g., an array of objects), if the value is set to a property such as the id, we must explicitly locate the corresponding option to set it as the selected value. This approach introduces boilerplate code and can lead to errors when interacting with the component. It negatively impacts the developer experience (DX).

It would be great to introduce a valueFromOption or a similar feature to streamline this process, removing the need for the additional code shown below. This enhancement would make the component more generic and adaptable to both flattened and non-flattened options.

Examples

 const selectedValue = flatOptions
  ? value
  : options.find((option) => option.id === value) ?? null;

  return (
    <Autocomplete
      // --- SNIP ---
      options={processedOptions}
      // --- SNIP ---
      value={selectedValue}
    />

Motivation

See above.

Search keywords: autocomplete, options, value

@aress31 aress31 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 26, 2024
@aarongarciah aarongarciah added the duplicate This issue or pull request already exists label Dec 27, 2024
@aarongarciah
Copy link
Member

Hey @aress31, thanks for contributing. I'm closing this issue since #23708 already exists. Feel free to provide more context if you think is needed.

@aarongarciah aarongarciah closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2024
@aarongarciah aarongarciah added component: autocomplete This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 27, 2024
@aress31
Copy link
Author

aress31 commented Dec 28, 2024

@aarongarciah the ticket you have linked is not related to my request. I would want to see a isValueEqualToOption.

@aarongarciah
Copy link
Member

You mentioned in the issue description the possibility of introducing a valueFromOption prop and the issue I linked talks about a getOptionValue prop, so I think they're related. If I'm not mistaken, both issues try to solve the problem of having the possibility of using "raw" values.

@aress31
Copy link
Author

aress31 commented Jan 8, 2025

@aarongarciah seems like a fix to #31192 would solve my issue. Using the options in getOptionLabel that is currently selected via the isOptionSelected check rather than the value would allow decoupling the value to process/send to backend to the text to display.

@aarongarciah
Copy link
Member

@aress31 yes, #31192 and #23708 are very related.

@aress31
Copy link
Author

aress31 commented Jan 8, 2025

@aarongarciah do you have an eta for the fix? It seems that the linked tickets have been ignored for a while.

@aarongarciah
Copy link
Member

aarongarciah commented Jan 8, 2025

No ETA, sorry. Base UI will be working on a new Combobox in 2025 and the intention is that Material UI then rewrites the Autocomplete on top of it. But we're far from that so I can't give any specifics. Not sure if we'll change the Autocomplete implementation before the rewrite to be honest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants