0

I'm trying to make an entry in a text field and display the value in the field for each letter. However, every time I type, I lose the focus in the field. I use the whole thing within a dialog component of Material-Design

 const [aendereEmail, setaendereEmail] = React.useState("");


    <Dialog
    onClose={userBearbeitenDialogClose}
    aria-labelledby="responsive-dialog-title"
    fullScreen={fullScreen}
    open={userBearbeitenDialog}
  >
    <DialogTitle id="simple-dialog-title">User bearbeiten</DialogTitle>
    <DialogContent dividers>
      <Col md={12} style={{ textAlign: "center", marginTop: "20px" }}>
          <TextField
            id="email"
            type="text"
            variant="outlined"
            label="eMail"
            onChange={(e) => setaendereEmail(e.target.value)}
            value={aendereEmail}
          />
        </Col>
      </Row>
    </DialogContent>
    <DialogActions>
      <Button
        color="primary"
        onClick={() => userBearbeitenSpeichern(aktuellerUser)}
      >
        übernehmen
      </Button>
    </DialogActions>
  </Dialog>
schorle88
  • 103
  • 6
  • I don't know what you're doing within your funciton, but here's a Stackoverflow answer that explains how to bind input to a field https://stackoverflow.com/a/42217730/8189504 – Yoni Ziv Aug 30 '20 at 12:55
  • It's a Hook in a function. – schorle88 Aug 30 '20 at 13:33
  • is TextField a custom component that you've created? If so, create a function handleChange(e) that takes e or event as a variable, and put setaendereEmail(e.target.value) in the handleChange(e). Then pass a reference of handleChange to the onChange prop. – Tom Bombadil Aug 30 '20 at 13:46
  • Hi @schorle88, What's the context of TextField? E.g. is TextField inside some map array? Can you add more info? The code that you added looks all good. – Luis Paulo Pinto Aug 30 '20 at 14:58
  • @Luis Paulo Pinto, no i don't use array for that. But all fields are inside a Dialog from Material Design – schorle88 Aug 30 '20 at 17:01
  • Can you add this part of the code? So we can see if there is something related to the issue. – Luis Paulo Pinto Aug 30 '20 at 17:16
  • Have edit my Post – schorle88 Aug 30 '20 at 17:26
  • Hi @schorle88, i simulate your code and it worked fine to me, when i type into TextField (inside Dialog), it updates the value and it keeps the focus. the only thing is i removed `` and `` as i don't know where it came from. Probably this strange behavior is related to some parent code. – Luis Paulo Pinto Aug 30 '20 at 17:41

0 Answers0