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] Mistake in error message #19163

Closed
nbspencer opened this issue Jan 10, 2020 · 5 comments · Fixed by #19177
Closed

[Autocomplete] Mistake in error message #19163

nbspencer opened this issue Jan 10, 2020 · 5 comments · Fixed by #19177
Labels
component: autocomplete This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@nbspencer
Copy link

Current Behavior 😯

Hi i'm Florian,

i've encountered a problem with the Autocomplete component that you can see here :
<Autocomplete id="conducteur" renderInput={ (params:RenderInputParams) => ( <TextField {...params} variant="standard" label="Veuillez choisir le conducteur" fullWidth /> )} renderOption={ (option: Person) => (<Typography noWrap>{${option.prenom} ${option.nom}}</Typography>) } options={persons} value={data.conducteur} onChange={(event: object,person: Person) => { setData( oldState => { oldState?.conducteur = person return oldState }) } } getOptionSelected={(option, value) => option.id === value.id } renderTags={(value: Person[], getTagProps) => value.map((option: Person, index: number) => ( <Chip variant="outlined" key={index} label={${option.prenom} ${option.nom}} {...getTagProps({ index })} /> ))} />
So i've put something in renderOptions but on my web browser i found this error :
image

but i checked the source code and getOptionLabel shouldn't be called if renderOption is fill.
Interesting or not when i put the property multiple it works fine but without it doesn't work.

Expected Behavior 🤔

The expected Behavior should be no error if renderOption is fill in the case of a standard autocomplete without multiple property and with renderOption filled.

Steps to Reproduce 🕹

I've done a codeSandBox to reproduce the problem simply :
https://codesandbox.io/s/tender-gates-13t51

Context 🔦

I'm trying to select a person into a list of person which his the driver of a car in my app.

i'm ont the latest version of material ui and lab.

if you need more details please tell me i'll will be please to help you.

Thank you guys for taking the time to read this.

@oliviertassinari
Copy link
Member

Ah, great catch! There is a small error in the warning message. Feel free to submit a pull request to fix it :).

diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index de0bfd292..f3ba2747b 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -216,7 +216,7 @@ export default function useAutocomplete(props) {
               `The component expect a string but received ${typeof optionLabel}.`,
               `For the input option: ${JSON.stringify(
                 newValue,
-              )}, \`getOptionLabel\` returns: ${newInputValue}.`,
+              )}, \`getOptionLabel\` returns: ${optionLabel}.`,
             ].join('\n'),
           );
         }

@oliviertassinari oliviertassinari added good first issue Great for first contributions. Enable to learn the contribution process. component: autocomplete This is the name of the generic UI component, not the React module! labels Jan 11, 2020
@oliviertassinari oliviertassinari changed the title [Autocomplete] getOptionLabel called even renderOption is fill [Autocomplete] Mistake in error message Jan 11, 2020
@nbspencer
Copy link
Author

Can you explain me why it doesn't put the tag with my selected value also btw ?

@oliviertassinari
Copy link
Member

I don't understand your problem. It's seems to be a feature request we have no plan to support.

@nbspencer
Copy link
Author

Well my question is why when i have a multiple autocomplete. And i put 2 elements in the list for example. They are already selected in the field. But when we don't have the property multiple and we have only one element. It doesn't select the element passed in the value.

@oliviertassinari
Copy link
Member

OK, then, the warning is here to help. Otherwise, you can ask for the solution on StackOverflow.

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Jan 11, 2020
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! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants