You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importReact,{Component}from'react';import{keyHandler,KEYPRESS}from'react-key-handler';constCloseButton=({ closeHandler })=><buttononClick={closeHandler}>Close</button>;constCloseOnEnterKeyOrButton=keyHandler({keyEventName: KEYPRESS,keyValue: 'enter'},ownProps=>{if(ownProps.closeHandler)ownProps.closeHandler();})(CloseButton);classParentextendsComponent{constructor(props){super(props);this.state={isOpened: true};}render(){if(this.state.isOpened){return(<div>
Some stuff
<CloseOnEnterKeyOrButtoncloseHandler={this.setState.bind(this,{isOpened: false})}/></div>);}returnnull;}}
This 2nd parameter to keyHandler would only be fired when enter would be pressed
The text was updated successfully, but these errors were encountered:
This feels like this can be the same possible solution that @villesau would like (described in #4 (comment)). As mentioned in that issue I'm open to improvements and more than happy to accept contributions
Awesome. I've been wanting to help out and work on this but I've been super busy (+ a little vacation). I've actually had this tab open since I opened this issue to remind myself about it haha
As of right now a component that gets wrapped by
keyHandler
has to expectkeyValue
, etc being passed down. That causes the component to be coupled withkeyHandler
if all you want to do is fire a callback that is on theprops
object. A way around this would be to allow anonKeyHandle
parameter be passed tokeyHandler
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:
This 2nd parameter to
keyHandler
would only be fired whenenter
would be pressedThe text was updated successfully, but these errors were encountered: