I am using material ui autocomplete in my project.
The option list is empty initially and on input change, the list will be populated.
So during the initial empty state, i need to show the placeholder like this in the options area.
On searching i found only the placeholder being populated in the input area( attached image) and not in the option list area.
Any idea on how to achieve this?
2
Answers
You can use the
noOptionsText
property of the Autocomplete component to achieve that. You can use it like thisnoOptionsText="Type to search"
. Note that it will show "Type to search" even when you have something typed and it has no result. To solve that you can conditionally add value in noOptionsText.In the below example I set value as "Type to search" when there is no input value. And I show "No result" otherwise.
You can check the sandbox here: https://codesandbox.io/p/sandbox/vigorous-meadow-dsdlm5
You can do this by specifying the value of the label property on the TextField component.