Skip to content
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

hotkeys in input #127

Closed
brietsparks opened this issue Aug 4, 2019 · 9 comments
Closed

hotkeys in input #127

brietsparks opened this issue Aug 4, 2019 · 9 comments
Assignees

Comments

@brietsparks
Copy link

Is there a way to handle a hotkey press inside an text input?

relevant: jaywcjlove/hotkeys-js#85 (comment)

@JohannesKlauss
Copy link
Owner

I'll investigate this and come back to you.

@JohannesKlauss JohannesKlauss self-assigned this Aug 20, 2019
@JohannesKlauss
Copy link
Owner

Well since the hook is just a wrapper function and the solution according to your linked issue is to use hotkeys.filter you could just use that. I am not quite sure how a working example would look like, since I don't quite understand the usage of hotkeys.filter in the mentioned issue.
Can you provide any more info on what the feature would look like to you?

@gagandeepgill
Copy link

gagandeepgill commented Aug 26, 2019

I did this and it works on input/select/textarea elements
reference: https://github.com/jaywcjlove/hotkeys#filter

import hotkeys, {HotkeysEvent} from 'hotkeys-js';
import {useCallback, useEffect} from "react";

type CallbackFn = (event: KeyboardEvent, handler: HotkeysEvent) => void;

export function useHotkeys(keys: string, callback: CallbackFn, deps: any[] = []) {
  const memoisedCallback = useCallback(callback, deps);

  useEffect(() => {
	hotkeys.filter = () => {
	  return true;
	}
    hotkeys(keys, memoisedCallback);

    return () => hotkeys.unbind(keys);
  }, [memoisedCallback]);
}

@JohannesKlauss
Copy link
Owner

@gagandeepgill pls reference this comment #146 (comment)
I think that we should make a parameter out of this, because otherwise it will be activated by default, which I don't think is expected behavior for users.

@Nolux
Copy link

Nolux commented Jan 18, 2020

Any updates on this? This is such a nice Hook

@JohannesKlauss
Copy link
Owner

@Nolux Sorry for not having any updates on this. Because of health issues I was forced to lay down programming for a bit. I try to get this done next week.

@Nolux
Copy link

Nolux commented Feb 21, 2020

No worries mate. I solved it using the hook mentioned above

@amitsetty
Copy link

Thanks for taking time out to update this. This hook is really helpful :)

@JohannesKlauss
Copy link
Owner

@Nolux This should already be possible. I'll update the docs on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants