question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocomplete options prop default

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
aaronhayescommented, Feb 16, 2020

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!

1reaction
aaronhayescommented, Feb 12, 2020

haha didn’t see that 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found