[英]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:我有一个 Material UI 自动完成功能,它根据您键入的 3 个字母选择其项目,例如:
You want to fetch all the Pedros in your database, then you type "Ped" and it brings you only results that start with "Ped".您想获取数据库中的所有 Pedro,然后键入“Ped”,它只会为您带来以“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:我希望它只在我输入 3 个字符后显示,并且在数据库中没有找到任何“Ped”,例如:
I tried to put a condition inside the prop "noOptionsText" but it did not work.我试图在道具“noOptionsText”中放置一个条件,但它没有用。 Does anyone know how to do it?有谁知道怎么做?
EDIT: Without using freeSolo, the option needs to be an object编辑:不使用freeSolo,选项需要是一个对象
Okay, I just found a way to answer my question.好的,我刚刚找到了一种方法来回答我的问题。
There's the prop "open" in Material UI's Autocomplete. Material UI 的 Autocomplete 中有道具“open”。 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.然后它只在我输入前 3 个字符时打开选项,否则它不会打开。 Plus, when I typed the 3 characters and there's no options, it will display the no options text.另外,当我输入 3 个字符并且没有选项时,它会显示无选项文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.