10 examples of 'react input on enter' in JavaScript

Every line of 'react input on enter' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
16onKeyPress(e) {
17 if (e.keyCode === 13) {
18 this.props.onEnter(this.state.value);
19 this.setState({ value: '' });
20 }
21}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

7onKeyDown(e) {
8 if (e.metaKey || e.ctrlKey) {
9 return;
10 }
11
12 switch (e.key) {
13 case 'Enter':
14 if (this.props.onEnter && this.props.onEnter !== _.noop) {
15 e.preventDefault();
16 this.props.onEnter(e);
17 }
18 break;
19 default:
20 break;
21 }
22}
37onInput(e){
38 this.setState({
39 value: e.target.value
40 })
41}
34handleInputChange(e) {
35 this.setState({ text: e.target.value });
36}
15onKeyDown({event}) {
16 if (event.metaKey || event.ctrlKey) {
17 return;
18 }
19
20 switch (event.key) {
21 case 'Enter':
22 if (this.props.onEnter && this.props.onEnter !== _.noop) {
23 event.preventDefault();
24 this.props.onEnter({event, component: this});
25 }
26 break;
27 default:
28 break;
29 }
30}
31handleEnter(ev: Event) {
32 if (this.options.blockReturn) ev.preventDefault();
33}
17HandleInput(event){
18 this.setState({
19 username : event.target.value
20 });
21}
32onKeyUp() {
33 this.check();
34 const { onKeyUp } = this.props;
35 onKeyUp && onKeyUp();
36}
33handleInput(e) {
34 if (e.keyCode === 13) {
35 e.preventDefault()
36 this.element.blur()
37 }
38}
28handleChangeInput(e) {
29 this.setState({
30 inputError: requiredField(e.target.value),
31 input: e.target.value
32 });
33}

Related snippets