[Autocomplete] `getOptionLabel` callback is getting the value instead of option object
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior šÆ
When using different types for options
and value
properties, the getOptionLabel
method is passed value instead of option object.
letās say Iām using following types:
type Option = { label: string; value: any; group?: string }
type Value = string;
Iām expecting getOptionLabel method always passed an Option type but thatās not the case. Thatās why the picked option can not be displayed properly.
getOptionLabel={(option) => option.label || "!!!"} //here sometimes Value type is passes instead of Option type.
isOptionEqualToValue={(option, value) => return option.value === value}
Expected behavior š¤
Always pass and option to getOptionLabel
as a param to be consistent.
Steps to reproduce š¹
Hereās a demo: https://codesandbox.io/s/controllablestates-material-demo-forked-0lekyg?file=/demo.js
Steps:
- Render a controlled Autocomplete component using different types for
options
andvalue
props. (object and string) - Utilize
isOptionEqualToValue
andgetOptionLabel
callback props
Context š¦
Iām trying to render options that are objects like {label:āLabelā, value:āsome valueā}, but I want to use the value of the selected option instead of the whole option object.
Your environment š
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Material-ui <Autocomplete /> getOptionLabel - passing empty ...
Material-UI: The `getOptionLabel` method of Autocomplete returned undefined instead of a string for [""]. I have 2 components. The child one is:
Read more >Autocomplete API - Material UI - MUI
Name Type Default
options * array
renderInput * func
autoComplete bool false
Read more >API - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >appendToBody | Vue Select
Callback to get an option key. If option is an object and has an id , returns option.id by default, otherwise tries to...
Read more >How to Use The Autocomplete Component in Material-UI
getOptionLabel ā Used to determine the string value for a given option. This is needed because our options array is an array of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For my use-case, I wanted to have the option as a string because my onChange uses the value to update an object in redux state, and I donāt want the label in there as well.
Okay I am re-opening the PR.