Material-ui: Enter key event is not fired in TextField when multiLine is false

Created on 18 Oct 2016  Â·  3Comments  Â·  Source: mui-org/material-ui

 <TextField
          onChange={ (event , value) => {
            console.log(event);
            }
          }
          hintText="Add User Expression"
        />

enter key event is not coming.

TextField question

Most helpful comment

@KARTIK01 If you add an onKeyPress event handler to the TextField, you can then check the character code for the enter key:

<TextField  onKeyPress={this._onKeyPress}/>
_onKeyPress(event) {
  if (event.charCode === 13) { // enter key pressed
    event.preventDefault();
    // do something here
  } 
}

All 3 comments

I can not understand your issue, @KARTIK01, can you please elaborate better and also provide a running snippet of what you are trying to accomplish?

i was trying to say that, in TextField onChange event is not called when user presses Enter key (↵)

 <TextField
          onChange={ (event , value) => 
            console.log(event)
            }
          hintText="Press Enter"
   />

how can i solve this. please help me out.

@KARTIK01 If you add an onKeyPress event handler to the TextField, you can then check the character code for the enter key:

<TextField  onKeyPress={this._onKeyPress}/>
_onKeyPress(event) {
  if (event.charCode === 13) { // enter key pressed
    event.preventDefault();
    // do something here
  } 
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanflorence picture ryanflorence  Â·  3Comments

rbozan picture rbozan  Â·  3Comments

ericraffin picture ericraffin  Â·  3Comments

ghost picture ghost  Â·  3Comments

mb-copart picture mb-copart  Â·  3Comments