简体   繁体   English

React/Redux:焦点在输入字段中丢失

[英]React/Redux: focus is lost in the input field

When you enter text in the field, focus is lost.在字段中输入文本时,焦点会丢失。 Why?为什么?

If remove the label prop, then the problem is solved.如果去掉标签道具,那么问题就解决了。 But a label is needed但是需要一个标签

<SimpleItem
  label={{ text: "Your Address" }}
  dataField="surname"
  editorOptions={{
    value: formEdit.surname,
    onValueChanged: ({ value }) => {
      addChange("surname", value);
    },
    valueChangeEvent: "keyup"
  }}
/>;

online demo: https://codesandbox.io/s/de-form-ezmmg在线演示: https : //codesandbox.io/s/de-form-ezmmg

I noticed that when using Label as child of SimpleItem (instead of prop), the input doesn't lose focus on keyup event (I tried digging in the docs, but I couldn't find a reason why this would happen):我注意到当使用Label作为SimpleItemSimpleItem (而不是 prop)时,输入不会失去对 keyup 事件的关注(我尝试在文档中进行挖掘,但我找不到会发生这种情况的原因):

<SimpleItem
  dataField="surname"
  editorOptions={{
    value: formEdit.surname,
    onValueChanged: ({ value }) => {
      addChange("surname", value);
    },
    valueChangeEvent: "keyup"
  }}
>
     <Label text="Your Address" />
</SimpleItem>

Code Sandbox 代码沙盒

Well like what jaycee discuss your field is re-rendering whenever you keyup.就像 jaycee 讨论的那样,您的字段在您键入时重新渲染。 I've tried to change the event to blur.我试图将事件更改为模糊。 Try this.尝试这个。 I hope it helps.我希望它有帮助。

在此处输入图片说明

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

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