Socket
Book a DemoInstallSign in
Socket

was-keypress-enter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

was-keypress-enter

A simple function to check if a keypress was the return/enter key. The function takes an event and returns a boolean.

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

was-keypress-enter (Node package)

Build Status Coverage Status

A function to check if a keypress was the return/enter key (either on the numpad or the main keyboard). The function takes an event (generated by a keypress for example) and returns a boolean.

Usage Example in the browser

<input type="text" id="input-field-one" />
document.getElementById('input-field-one').addEventListener('keydown', function(e) {
  if(wasKeypressEnter(e)) {
    // enter was pressed
  }
  else {
    // a key was pressed but it wasn't enter
  }
});

Usage example in react

import wasKeypressEnter from 'was-keypress-enter';

export class CustomUserInput extends React.Component {

    constructor(props) {
      super();
    }
    
    handleClick(e) {
      //the element was clicked
    }
    
    handleKeyPress(e) {
      if(wasKeypressEnter(e) {
        //the keypress was the enter key - do something
      }
    }
    
    render() {
      return (
        <CustomComponent tabIndex="0" onClick={this.handleClick} onKeyPress={this.handleKeyPress} />
      );
    }
}

FAQs

Package last updated on 26 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts