Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onKeyPress and onKeyDown not working #109

Open
WilliamCSA04 opened this issue Sep 12, 2017 · 5 comments
Open

onKeyPress and onKeyDown not working #109

WilliamCSA04 opened this issue Sep 12, 2017 · 5 comments

Comments

@WilliamCSA04
Copy link

Hello, Im having a problem with onKeyPress and onKeyDown. I did create a component called Input, and have this line:

<MaskedInput id="message" mask={this.props.mask} type={this.props.type} className="inpt inpt-default" placeholder={this.state.text} onBlur={this.onBlur} onFocus={this.onFocus} name={this.props.name} onChange={this.onChange} onKeyPress={this.props.onKeyPress} value={this.state.message}/>

And Im calling the Input component like this:

<Input ref="input" type="phone" name="phone" mask="(11) 11111 1111" onClick={this.inputOnClick} onKeyPress={this.handleKeyPress}/>

handleKeyPress(event){
     if(event.key === "Enter"){
      this.processUserInput(event.target.name);
     }

}

I know that my handleKeyPress function is working for two reasons, first, is working at other regular inputs, second, I had replaced use onKeyPress={this.props.onKeyPress} for onKeyUp={this.props.onKeyPress} and worked.

@javierggi
Copy link

Did you get this to work? I am stuck with the same problem.

@WilliamCSA04
Copy link
Author

Not really, I had to use KeyUp instead.

@m-salamon
Copy link

Im having the same issue, can anyone help please

@cooperjones
Copy link

Similar issue here. onKeyDown and onKeyUp both work, but onKeyPress in the same context doesn't function. Would love to have a fix for this!

@Byron2016
Copy link

You can find the solution here:

https://gist.github.com/krambertech/76afec49d7508e89e028fce14894724c

handleKeyPress(event){ if(event.key === "13"){ this.processUserInput(event.target.name); } }

<Input ref="input" type="phone" name="phone" mask="(11) 11111 1111" onClick={this.inputOnClick} onKeyPress={(e) => this.handleKeyPress(e)}/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants