简体   繁体   中英

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

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):

<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. I've tried to change the event to blur. Try this. I hope it helps.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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