Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Material-UI Autocomplete customize `no options` text

I'm looking at this example of Autocomplete provided by MaterialUI

https://codesandbox.io/s/81qc1

I was wondering how I can display a "No options found" message if no results are found.

like image 913
shxpark Avatar asked Apr 03 '20 21:04

shxpark


People also ask

How do you style material UI autocomplete?

The Material-UI Autocomplete component and its Popper component can be styled by targeting built-in MUI styling APIs. The Popper is also called a dropdown or listbox. The difference is that Popper is the positioning element while Listbox is the visible list element.

How do I change the height of autocomplete material UI?

How can you reduce the height of the autocomplete component of material-UI? To reduce the height, I used the size attribute and removed the label attribute. Make sure not to override the params provided by the Autocomplete component on your TextField component, which already include things like InputProps .

What is clearOnBlur?

clearOnBlur={true} helps to clear the value of the autocomplete component when it loses focus.

How do I set default value in autocomplete MUI?

MUI Autocomplete Default Value If you need to set the initial value for your Autocomplete component and then never programmatically update it again, the best option is the defaultValue prop. This prop accepts a value that only gets rendered until an option is selected from the Autocomplete's dropdown list.


1 Answers

Use props noOptionsText for Material-UI Autocomplete

Text to display when there are no options. For localization purposes, you can use the provided translations.

  • Ref: Document of Autocomplete API
import Autocomplete from '@material-ui/lab/Autocomplete';

<Autocomplete
  noOptionsText={'Your Customized No Options Text'}
  ...
/>

enter image description here

like image 176
keikai Avatar answered Sep 26 '22 03:09

keikai