简体   繁体   English

如何在 MaterialUI 自动完成中仅显示 NoOptionsText 条件

[英]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.

相关问题 仅当条件为真时如何启用/可见垫自动完成 - How to enable/visible mat-autocomplete only if condition gets true 仅当满足某些条件时,JQuery才会自动完成 - JQuery autocomplete only if certain condition is met 数据可用时,MaterialUI 组件不会自动完成 - MaterialUI Compoent does not AutoComplete when data is available 如何在 MaterialUI 中使网格居中 - How to center a grid in MaterialUI MaterialUI 是如何做到这一点的? - How does MaterialUI do this? 如何仅按条件在Javascript React中显示语言项目 - How to show language item only by condition in Javascript React 仅在有5个结果时显示YUI自动填充页脚 - Only show YUI autocomplete footer when there are 5 results 如何通过仅在某些路径上进行布线的材质UI渲染抽屉? (reactjs)(materialui) - How do i render the drawer from material UI with routing only on certain routes? (reactjs)(materialui) 仅当用户输入特定字符(例如@)时,才如何使用引导程序提前显示自动完成选项? - How to show autocomplete options using bootstrap typeahead only when user enters a particular character like @? 如何调整 MaterialUI SVG 图标的大小? - How to resize MaterialUI SVG icon?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM