Giter Club home page Giter Club logo

react-key-handler's People

Contributors

ayrton avatar fmal avatar gforge avatar greenkeeperio-bot avatar hedgehogby avatar jamesfzhang avatar leocavalcante avatar rstankov avatar stevemao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-key-handler's Issues

v1.1.0 window is not defined

ReferenceError: window is not defined
    at Object.<anonymous> (/app/node_modules/react-key-handler/dist/index.js:1:258)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.zkQZ (/app/public/assets/webpack:/external "react-key-handler":1:1)
    at __webpack_require__ (/app/public/assets/webpack:/webpack/bootstrap cfaabd2047db963ff127:25:1)
    at Object.N7P3 (/app/public/assets/webpack:/frontend/ph/components/App.js:3:1)
    at __webpack_require__ (/app/public/assets/webpack:/webpack/bootstrap cfaabd2047db963ff127:25:1)
    at Object.lYkL (/app/public/assets/webpack:/frontend/server/routes/ssr.js:1:1)
    at __webpack_require__ (/app/public/assets/webpack:/webpack/bootstrap cfaabd2047db963ff127:25:1)
    at Object.TDg2 (/app/public/assets/webpack:/frontend/server/ssr.js:17:1)
    at __webpack_require__ (/app/public/assets/webpack:/webpack/bootstrap cfaabd2047db963ff127:25:1)
    at Object.0 (/app/public/assets/server.js:2373:18)
    at __webpack_require__ (/app/public/assets/webpack:/webpack/bootstrap cfaabd2047db963ff127:25:1)
    at /app/public/assets/webpack:/webpack/bootstrap cfaabd2047db963ff127:90:1
    at Object.<anonymous> (/app/public/assets/server.js:95:10)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

Firefox keypress == 0 - amend with which

While keyCode together with keepress returns 0 in Firefox (https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode). This can be mitigated to using a fallback thgrough the event.which argument:

if (!isNullOrUndefined(keyCode)) {
  // Firefox handles keyCode through which 
  const code = event.keyCode || event.which;
  return keyCode === code;
}

Although the change should probably be towards just `.code`: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code

Key code list

There's no point in maintaining our own list of key code names, it's incomplete anyway. We should try and find a simple npm package that does this for us.

The following project looks promising: https://github.com/andrepolischuk/keycodes

If you're interesting in working on this, let me know :)

Update code according to React 15.5

Hello, Ayrton!

As you most likely know, React was updated to 15.5 and React.PropTypes and React.createClass were extracted into their own packages. So now React shows warning in case you use PropTypes in the old way.
Here you can find details.

I made a small pull request #103 to fix this. It would be great if you could find a time to check and merge it and release a new version with React 15.5 support.

Broken when using Draft-js

Since Draft-js doesn't use default input or textareas, typing in its editor causes key handlers here to be triggered. Not quite sure whose "fault" it is, but just wanted to bring this to attention.

Fires multiple times for multiple instances

I have a component that contains this:

<KeyHandler
     keyEventName={KEYPRESS}
     keyValue='Enter'
     onKeyHandle={onKeyHandler}
/>

So, when i make multiple instances of my React component that contains this, I'm finding that onKeyHandler fires for ALL when ONE of them receives a keypress event. Any idea why this is happening or how to prevent it?

Fires twice if props/state changes causes re-mapping of the fired key

I've found that if the parent components props/state changes when an event is fired it will re-trigger the same event, i.e. firing twice. To be more specific, it happened when a new react-key-handler component with the same key binding was created on a different element. To illustrate the components

[button one, key 1], [button two, key 2], [button three, key 3]

when I pressed 2 the button one would disappear and the keys would with new bindings:

[button two, key 1], [button three, key 2]

I've solved this by adding a setTimeout(.., 0) to the call. This could possibly be activated through a prop that wraps the onKeyHandle in a setTimeout function.

Prevent default (Browser arrow scrolling)

I would like to use arrow keys for moving elements. This works great. But when I press 'up' and 'down' keys the browser scroll is also activated.

How can I prevent this default behavior? I'm working with React components:

<KeyHandler keyEventName={KEYPRESS} keyValue="ArrowLeft" onKeyHandle={this.moveEventLeft} />

The function doesn't seem to have an event parameter.

Thanks !

Alt key with any Alphabet combination is not working

<KeyHandler keyValue="i" onKeyHandle={this.someMethod} />

someMethod(event) {
console.log(event.altKey);
}

someMethod is not getting invoked when pressing alt + i where as alt works fine with special keys like Arrows, function keys etc.

ESC Doesn't work

<KeyHandler keyEventName={KEYPRESS} keyCode={27} onKeyHandle={() => this.dismissOverlay()} />

That's what I have and it doesn't work. If I put 13 it'll work fine with Enter.

Have the higer-order component accept an onKeyHandle parameter

As of right now a component that gets wrapped by keyHandler has to expect keyValue, etc being passed down. That causes the component to be coupled with keyHandler if all you want to do is fire a callback that is on the props object. A way around this would be to allow an onKeyHandle parameter be passed to keyHandler that could look like (ownProps, keyValue, keyEventName) => void or something akin to that.

Just want to open the discussion of any pros/cons of this approach

Here's an example:

import React, { Component } from 'react';
import { keyHandler, KEYPRESS } from 'react-key-handler';

const CloseButton = ({ closeHandler }) => <button onClick={closeHandler}>Close</button>;

const CloseOnEnterKeyOrButton = keyHandler(
  { keyEventName: KEYPRESS, keyValue: 'enter' },
  ownProps => {
    if (ownProps.closeHandler) ownProps.closeHandler();
  }
)(CloseButton);

class Parent extends Component {
  constructor(props) {
    super(props);
    this.state = { isOpened: true };
  }
  render() {
    if (this.state.isOpened) {
      return (
        <div>
          Some stuff
          <CloseOnEnterKeyOrButton closeHandler={this.setState.bind(this, { isOpened: false })} />
        </div>
      );
    }
    return null;
  }
}

This 2nd parameter to keyHandler would only be fired when enter would be pressed

Combination CTRL + SHIFT + A not work

The 2 key combination works well. e.g. ctrl+A, ctrl+C
but when press key ctrl + shift + A
It only files event: event.ctrlKey ===true + event.keyCode === shiftLeft
But what I expect is: event.ctrlKey ===true + event.shiftKey=== true + event.keyCode ==='a'

is there anything wrong? or this react-key-handler cannot support 3 key combination?
<KeyHandler
keyEventName={KEYDOWN}
keyValue={['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight', 'Control', 'Meta', 'Delete',
'Backspace', 'a', 'c', 'e', 'p', 's', 'v', 'x']}
onKeyHandle={this.keyDownEventHandler}
/>

I do not understand the real usage of this lib and its API

Sorry for the harsh/clumsy title, but why this API?

I mean, If I understand correctly, in the API, here

export default keyHandler({ keyEventName: KEYPRESS, keyValue: 's' })(Demo);

It seems that the component explicitly waits for a specific KEYPRESS to be s in order for the component to have this.props.keyEventName and this.props.keyValue not null (but 115 and s).

Why that choice?

I was more expecting a HOC/decorator that would give me in props any keyboard events with their value, my component having to deal with that specifically in componentWillReceiveProps() or componentWillUpdate(), but this current API seems very limiting.

Unless I'm missing the big picture here :)

Thanks for your lights

Support for multiple key codes

We need to add support to listen to more than one key code, e.g.:

const A = 65;
const B = 66;

keyHandler({ keyCodes: [A, B] })(MyComponent);

could probably decorate a property keyCodes to MyComponent:

{
  alt: true,
  ctrl: false,
  meta: false,
  shift: false,
  65: true,
  66: false,
}

Alternatively, the following projects looks promising:

If you're interesting in working on this, let me know :)

Won't work for arrow keys

It works well for letter keys but won't work for special keys such as arrow keys. I also tried keyCode prop but no help.

<KeyHandler keyEventName={KEYPRESS} keyValue="a" onKeyHandle={() => console.log('a')} />
<KeyHandler keyEventName={KEYPRESS} keyValue="ArrowLeft" onKeyHandle={() => console.log('ArrowLeft')} />

0.2.0

The road to 0.2.0:

  • #17
  • Add prop types
  • Deprecate keyName
  • Throw invariant
  • Loosen react dependency for future react versions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.