在字符串中间键入字母将光标带回末端 - 材料UI
我实现了一个Chipinput组件,当焦点将其表现为字符串时,将通过逗号引入的芯片转换为芯片组件。除了一个问题外,所有功能都很好。当我输入多个单词时,我想在两者之间添加一个新字母时,光标将我带到了最后,但我希望光标保持在同一位置。
有人可以帮我吗?谢谢。
这是我的Stackblitz link link
I implemented a ChipInput component which when focused will behave a string and onBlur will be transformed into a Chip component with the chips introduced by a comma. All works well except for a single issue. When I type in multiple words, and I want to add a new letter in between, the cursor takes me to the end but I want the cursor to stay at the same position.
Could someone please help me out? Thanks.
This is my Stackblitz link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此问题之所以发生,是因为
chipInput
每次name
inindex.tsx.tsx
中的值都会更改名称
。解决此问题的一种解决方案是更改
状态>
内部chipinput.tsx
已更新。chipinput.tsx
中删除以下使用
代码:state state
的初始值更改为:set> setState
语句deletechip
函数to:deletechip
函数将看起来像:到
的
OnInputChange
prop的末尾
组件。chipinput.tsx
中的autocompleteoninputChange
prop将看起来像:This issue occurs because the
ChipInput
component is rerendered every time there is a change in the value ofname
inindex.tsx
.One solution to this problem is to change the way
state
insideChipInput.tsx
is updated.useEffect
code fromChipInput.tsx
:state
to:setState
statement thedeleteChip
function to:The
deleteChip
function would then look like:to the end of the
onInputChange
prop of theAutocomplete
component inChipInput.tsx
. TheonInputChange
prop would then look like: