简体   繁体   English

如何将单词更改为文本字段或输入字段的下拉菜单?

[英]How to change a word into drop down menu in text field or input field?

I am building custom spellchecker in React.js and I am stuck in changing the word into the dropdown menu to select the correct word. 我正在React.js中构建自定义拼写检查器,并且一直坚持将单词更改为下拉菜单以选择正确的单词。 Please help. 请帮忙。

I am doing research on it from a long time but to no avail. 我一直在对此进行研究,但无济于事。

Since you're looking for a general approach, here's how I would approach this problem. 由于您正在寻找一种通用方法,因此这是我将如何解决此问题的方法。

When a word is misspelled, replace it with a React component containing two children: the text displaying the misspelled word, and your 'replacement word' select box. 当单词拼写错误时,将其替换为包含两个子元素的React组件:显示拼写错误单词的文本和“替换单词”选择框。 Fill the select with possible replacement words. 用可能的替换词填充选择。

Use a React Synthetic Event ( onMouseOver ?) to toggle between displaying the components-- select on mouse over, display text otherwise. 使用React Synthetic Event( onMouseOver事件)( onMouseOver ?)在显示组件之间切换-在鼠标悬停时选择,否则显示文本。 I might suggest onClick , since I think that's easier to use and more mobile-first. 我建议使用onClick ,因为我认为它更易于使用,并且更适合移动设备。

When the user selects one of the replacement words, the word is no longer evaluated as misspelled, and the entire parent component unmounts, replaced by the correctly spelled word. 当用户选择替换单词之一时,该单词将不再被评估为拼写错误,并且整个父组件将卸载,并由正确拼写的单词替换。

React Synthetic Events docs 反应合成事件文档

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

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