简体   繁体   中英

How to show NoOptionsText only with condition in MaterialUI Autocomplete

I have a Material UI autocomplete that selects its items based on the 3 letters you type, for example:

You want to fetch all the Pedros in your database, then you type "Ped" and it brings you only results that start with "Ped".

The problem is when I click in the auto complete it immediately shows the message "No options" like这张照片

And I want it only to show after I typed 3 characters and it did not find any "Ped" in the database like:

在此处输入图片说明

I tried to put a condition inside the prop "noOptionsText" but it did not work. Does anyone know how to do it?

EDIT: Without using freeSolo, the option needs to be an object

Okay, I just found a way to answer my question.

There's the prop "open" in Material UI's Autocomplete. I just put a condition like:

open={lenght >= 3}

Then it only opens the options when I've typed the first 3 characters, otherwise it won't open. Plus, when I typed the 3 characters and there's no options, it will display the no options text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM