-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support keydownGlobal #71
Conversation
@sheldonrong could you revert the formatting changes? it makes it a bit hard to grok what actually changed. |
@glortho no problem, ill work on it today. |
via the @keydownGlobal decorator
@glortho updated. Since we use TypeScript, I also wrote a simple type definition file (not in this commit), not sure if you take it or not. I can submit it to |
thank you @sheldonrong! this is looking good, though i have a few questions for us to discuss (cc @salmanm):
|
And thank you for creating a type def @sheldonrong ! I think it's probably good to just include it here since it's so small. |
I'm voting for firing both at this stage. I think if developer opt for using I haven't tried when using In our case, we have a navigation header that is sticky at the top of the app, which I need to use the |
You're right, devs ideally shouldn't have duplicate bindings across local + global but good to have consistency either way. So I think what we need then is to continue through the loop here https://github.com/glortho/react-keydown/pull/71/files#diff-3bf35cd41da51153dcca3003656f7c67R90 to potentially match multiple bindings - exactly one local binding (the most recently activated one), and one or more global bindings. Does that sound right? |
ill think about it and get back to you tomorrow :) |
@@ -16,7 +16,7 @@ import { ALL_KEYS } from '../lib/keys'; | |||
* @param {array} [keys] The key(s) bound to the class | |||
* @return {object} The higher-order function that wraps the decorated class | |||
*/ | |||
function componentWrapper( WrappedComponent, keys = ALL_KEYS ) { | |||
function componentWrapper( WrappedComponent, keys = ALL_KEYS, options={global: false} ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: All empty class decorators will create a new object. Perhaps we should have a defaultOptions
above and just use that if not supplied.
(Is find if you don't do it now, I'll add when I work on debounce)
Edit: I see that you're not taking options
from the user, so its fine for now but will need to be changed.
} | ||
|
||
function keydownGlobal( ...args ) { | ||
return _decorator( methodWrapper, { global: true }, ...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will clash a bit when we start taking options
from the decorator. options
will then be last arg.
1 & 2) I think A hypothetical case could be, say I have a modal popup with Escape key bound to close it. The popup shows a grid with some data in it. The grid is editable and on overtyping, I show the
|
WIP or POC
I don't have unit test at this stage, but initial testing says it is good.
This is to address issue #69
Also, formattring kinda screw up, but if you are happy with the concept, I can fix these trivial issues :)