-
Notifications
You must be signed in to change notification settings - Fork 66
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 throws error message #2976
Comments
optionLabel is required when using optionComponent, see storybook. |
Agree @Chibuzor-Nwemambu, it doesn't matter much whether or not this is categorised as a bug, the component is poorly described. @oddvernes I'd expect |
@Chibuzor-Nwemambu have you been able to make this work? I need to know if I can close this issue. By the way I now notice you say you are on version 0.30.0 but optionComponent was only added in 0.31.0 just in case that is the problem🤔 |
@oddvernes thank you! I wasn't looking for a "Customized option component", so I guess that's why I couldn't find it there. It wasn't intuitive to me why I should get the error, though.. I think I understand more how it was meant to be used now - I am using objects as options, but didn't get any ts-errors by doing so. When is |
@oddvernes I guess if |
Yes we should definetly try and make typescript complain when optionlabel is not present if options are objects (and not when they are strings) 👍 For now i have updated the prop table in storybook for optionsLabel |
@oddvernes How about this? type Options<T extends Array<unknown>> = T extends Array<string>
? Array<string>
: { objects: T; label: (option: T[number]) => string } Defining options in Autocomplete: Example, using type StringType = Options<string[]> // string[]
type ObjectType = Options<
{
label: string
symbol?: string | undefined
trend?: string | undefined
}[]
> /*
{
objects: {
label: string;
symbol?: string | undefined;
trend?: string | undefined;
}[];
label: (option: {
label: string;
symbol?: string | undefined;
trend?: string | undefined;
}) => string;
}
*/ Then you'd define options like this when you're using objects as options (it type errors if you don't include label and informs about the missing properties) |
@oddvernes Yes I have, thanks a lot for the response |
Describe the bug
Autocomplete throws error message when optionsComponent is used.
A clear and concise description of what the bug is.
In order to use Autocomplete, you need either an optionLabel or optionComponent, and this seemed to work fine. However, by Wednesday 12th or Thursday 13th July(not sure which exactly), I noticed that my component throws an error saying optionComponent is not a function. It also throws an error requiring
optionsLabel
even thoughoptionsComponent
is provided. It is almost like it doesn't recogniseoptionComponent
.Another weird thing I noticed is that this only occurs in local build but it seems to work okay in other environments
Steps to reproduce the bug
1.Create an Autocomplete dropdown
2.use
optionComponent
and notoptionLabel
3.
4.
Expected behavior
A dropdown should appear with individual items from my array
A clear and concise description of what you expected to happen.
Specifications
Additional context
Add any other context or screenshots about the bug. An example in CodeSandbox is very helpful
The text was updated successfully, but these errors were encountered: