[英]Reactjs : give text input to select element(combo box)
I am trying to implement a react js select element. 我正在尝试实现react js select元素。 I am giving a set of options to that element such that the user can select.
我给该元素提供了一组选项,以便用户可以选择。 In addition to that I need to add a place holder to that element and make it able to type values and enter as in a text box.
除此之外,我需要为该元素添加占位符,并使其能够键入值并在文本框中输入。 Then the users can either enter custom values to it or select an element from the drop down.
然后,用户可以向其输入自定义值,也可以从下拉列表中选择一个元素。
Below is the code snippet I used for implementing the select element. 下面是我用于实现select元素的代码片段。 But it only allows selecting.
但它只允许选择。 Can anyone help me to implement a select element which allows inputting text and place holder.
任何人都可以帮我实现一个允许输入文本和占位符的选择元素。
<select className="form-control form-control-sm" ref="LayerL6Select" name="LayerL6Select" id="LayerL6Select">
<option value="1">Apple</option>
<option value="2">Mango</option>
</select>
If you looking for short time solution. 如果你寻找短时间的解决方案。 I would suggest following react-select library which helps you to achieve what you want.
我建议遵循react-select库,它可以帮助你实现你想要的。
https://react-select.com/home https://react-select.com/home
else if you ask this for your personal learning here its source code, you could learn from it source code. 否则,如果您在此处询问此个人学习的源代码,您可以从中学习源代码。
https://github.com/JedWatson/react-select https://github.com/JedWatson/react-select
You should use <input>
followed by <datalist>
.Here is example in html you can convert in into react. 您应该使用
<input>
然后使用<datalist>
是html中的示例,您可以将其转换为react。 Note that id
attribute of <datalist>
should be added list
attribute of the <input>
注意
<datalist>
id
属性应该添加<input>
list
属性
The
datalist
element is hooked up to aninput
element using thelist
attribute on the input element使用
input
元素上的list
属性将datalist
元素连接到input元素
<input placeholder="myplaceholder" list="opts"/> <datalist id="opts"> <option>One</option> <option>Two</option> <option>Three</option> </datalist>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.