Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

on enter key press react

onKeyPress={(e) => e.key === 'Enter' && handleSearch()}
Comment

capture enter button react input

const Enter = () => {
  	const handle = () => console.log('Enter pressed');
  
	return <input type="text" onKeyDown={e => e.key === 'Enter' && handle} />;
};
Comment

react detect enter key

var Input = React.createClass({
  render: function () {
    return <input type="text" onKeyDown={this._handleKeyDown} />;
  },
  _handleKeyDown: function(e) {
    if (e.key === 'Enter') {
      console.log('do validate');
    }
  }
});
Comment

on enter key press react js

  useEffect(() => {
    const listener = event => {
      if (event.code === "Enter" || event.code === "NumpadEnter") {
        console.log("Enter key was pressed. Run your function.");
        event.preventDefault();
        // callMyFunction();
      }
    };
    document.addEventListener("keydown", listener);
    return () => {
      document.removeEventListener("keydown", listener);
    };
  }, []);
Comment

search to enter key react

class CartridgeShell extends React.Component {

   constructor(props) {
      super(props);
      this.state = {value:''}

      this.handleChange = this.handleChange.bind(this);
      this.keyPress = this.keyPress.bind(this);
   } 
 
   handleChange(e) {
      this.setState({ value: e.target.value });
   }

   keyPress(e){
      if(e.keyCode == 13){
         console.log('value', e.target.value);
         // put the login here
      }
   }

   render(){
      return(
         <input value={this.state.value} onKeyDown={this.keyPress} onChange={this.handleChange} fullWidth={true} />
      )
    }
}

ReactDOM.render(<CartridgeShell/>, document.getElementById('app'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: access-control-allow-origin nodejs express 
Javascript :: Bootstrap jquery popper and js cdn 
Javascript :: how to know connected internet in js 
Javascript :: random id js 
Javascript :: execute javascript on page load jquery 
Javascript :: javascript start function on load 
Javascript :: npx create-react-app 
Javascript :: how to get the value of dropdown in jquery 
Javascript :: jquery script tag 
Javascript :: js remove undefined from array 
Javascript :: javascript screen size 
Javascript :: check if date time string is invalid date js 
Javascript :: remove previous datatable instance 
Javascript :: acces store from vue console javascript 
Javascript :: set port in react app 
Javascript :: localsstorage array append element 
Javascript :: jquery disable all input form 
Javascript :: mouseover angular 6 
Javascript :: get select2 selected value 
Javascript :: how to pad string js 
Javascript :: make minutes have 0 in javascript 
Javascript :: js for each element class 
Javascript :: javascript sort by numerical value 
Javascript :: javascript array split chunk 
Javascript :: node js procfile heroku starter 
Javascript :: jquery check if input is empty on submit 
Javascript :: console.log object to json 
Javascript :: javascript scroll to end of div 
Javascript :: js check if date is today 
Javascript :: uuid generator pure javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =