-
Notifications
You must be signed in to change notification settings - Fork 162
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
prevent all event propagation in a certain context #31
Comments
Same issue as #14. I'm resolving for now with the following:
but definitely it feels hacky |
To try and confirm your requirement are you looking for some sort of "bubble isolation" where you will not trigger any sequences (and therefore handlers) at any parent level above? Eg. maybe something like
As a side note I'm a bit mythed by this since I thought mousetrap would not fire from input events by default as documented here: https://craig.is/killing/mice#api.stopCallback |
You are correct that that is the default behavior of Mousetrap when bound to the
Interestingly enough, it seems you aren't thrilled about binding to a specific element as suggested by the comment in this code in HotKeys.js:
If you chose the |
It took me about three hours to figure out how I could use
See https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute for a little more info. |
Interesting - I was looking at a similar (I think from the description) scenario where I want HotKeys to manage my inner components and their state, but prevent certain key events from bubbling up if they are handled by HotKeys. In my case, a user scrolls up and down a table component but in this case I don't want the up and down keys affecting the cursor position in my input box - I resolved this internally, but have been trying to conceptualise a better more generic solution. |
Thanks for publicizing your solution @JoshuaCWebDeveloper I will be taking this into consideration when we re-work the api for v1. NB. Hoping to transfer ownership of this project into my company so we can have an active team maintain it as day-to-day rather than being a neglected project on the side. |
Thanks @JoshuaCWebDeveloper was looking for the same solution. Mousetrap does prevent shortcuts on inputs, but it always bypass this prevention if the trap target is a parent of the input:
|
edit what works best for me is to handle ref of Hotkeys and assign directly callback to prototype
|
Not sure if this is better put in
mousetrap
orreact-hotkeys
, but I have the following use case.I have an input field that I want particular hotkeys to work on, so I have
However, because I have hotkeys further up the stack that would conflict with entering text in the input, I want to use only hotkeys in the immediately surrounding context, and not forward events up.
Is this possible?
The text was updated successfully, but these errors were encountered: