简体   繁体   English

文本字段使用 react-select 自动建议用户名

[英]Text field auto suggest username with react-select

I would like to create a React component using react-select to auto suggest usernames in a text field similar to the one I am typing in now.我想使用 react-select 创建一个 React 组件,以在类似于我现在输入的文本字段中自动建议用户名。

The feature would be triggered when a '@' is typed at the beginning of a word or by itself, than the drop down select options will be shown (similar to facebook's and github username suggest for text fields).当在单词的开头或单独输入“@”时,将触发该功能,然后将显示下拉选择选项(类似于 facebook 和 github 用户名建议的文本字段)。 While the options are shown the user would still be able to type, with the arrow keys, they can select an option.当显示选项时,用户仍然可以键入箭头键,它们可以选择一个选项。 The option would than replace the word with its value prefixed with a '@' and postfixed with an empty space.该选项将用其值替换单词,前缀为“@”,后缀为空格。

All the tutorials I have found only have react-select being used with single line inputs similar to the Tags input below.我发现的所有教程都只将 react-select 与单行输入一起使用,类似于下面的标签输入。

desired result想要的结果

I don't think react-select is the correct plugin you should use given the examples you mentioned. 考虑到您提到的示例,我不认为react-select是正确的插件。 Maybe you should take a look to a library like react-textarea-autocomplete (you can try a live example here ). 也许您应该看一下像react-textarea-autocomplete这样的库(您可以在此处尝试一个在线示例)。

for username, you can use this attribute: autocomplete="username"对于用户名,您可以使用此属性: autocomplete="username"

you can check for more options here: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete您可以在此处查看更多选项: https : //developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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