Autocomplete options prop default
See original GitHub issueDescribe the bug
Autocomplete
will error when options
is undefined
. We should make the default []
. This is how material-ui handle it.
To Reproduce
Steps to reproduce the behavior:
Set options
on Autocomplete
component to undefined.
Expected behavior Expect an empty options list instead of an error.
Versions
Happening since >=1.8.0
. Works fine on 1.7.3
Desktop (please complete the following information):
- OS: Any
- Browser: Any
- Version: Any
Smartphone (please complete the following information):
- Device: Any
- OS: Any
- Browser Any
- Version Any
Additional context
AutocompleteWrapper
src/Autocomplete.tsx:78
75 | // yuck...
76 | let defaultValue: any = undefined;
77 | if (value !== undefined && value !== null) {
> 78 | options.forEach((option: any) => {
| ^ 79 | const optionValue = getOptionValue(option);
80 | if (multiple) {
81 | if (!defaultValue) defaultValue = [];
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Autocomplete - How can I set a default value?
I just had to set the "value" prop using the exact item from my options array. This way componentDidMount and getOptionSelected aren't needed....
Read more >MUI Autocomplete Get and Set Values, Default Values, and ...
This prop accepts a value that only gets rendered until an option is selected from the Autocomplete's dropdown list. When TypeScript is enabled, ......
Read more >Autocomplete API - Material UI
Name Type Default
options * array
renderInput * func
autoComplete bool false
Read more >A Guide on Material UI AutoComplete in React
export default function CustomInputAutocomplete() { return ( <label> ... You can sort the MUI Autocomplete options with the groupBy prop.
Read more >Get, Set, and Default Values in MUI Autocomplete and TextField
Do you want to build a full MUI app from beginning to end, learn every aspect of the sx prop, styled API, and...
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
Turns out options is now required in material-ui now https://github.com/mui-org/material-ui/pull/19648 so even less reason to change!
haha didn’t see that 👍