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

feat(onKeyStroke): new functions #416

Merged
merged 4 commits into from Apr 4, 2021
Merged

feat(onKeyStroke): new functions #416

merged 4 commits into from Apr 4, 2021

Conversation

yyyanghj
Copy link
Contributor

@yyyanghj yyyanghj commented Apr 4, 2021

Add the onKeyStroke function to listen for keyboard events. Inspired from react-use.

@antfu
Copy link
Member

antfu commented Apr 4, 2021

Preferred to name it onKeyStroke, and more over, we could have onKeyDown onKeyUp onKeyPressed alias.

And for the arguments, I think we can put eventName, target, and also passive into the options field. Meaning:

function onKeyStroke(key, handler, options) { }

To make this even more useful, we could also have modifier support ^+P or Ctrl+Shift+P, but what would be a bit out of scope, which we could have later as onHotKeys or onShortcuts

@yyyanghj yyyanghj changed the title feat: add useKey function. feat: add onKeyStroke function. Apr 4, 2021
@yyyanghj
Copy link
Contributor Author

yyyanghj commented Apr 4, 2021

Preferred to name it onKeyStroke, and more over, we could have onKeyDown onKeyUp onKeyPressed alias.

And for the arguments, I think we can put eventName, target, and also passive into the options field. Meaning:

function onKeyStroke(key, handler, options) { }

To make this even more useful, we could also have modifier support ^+P or Ctrl+Shift+P, but what would be a bit out of scope, which we could have later as onHotKeys or onShortcuts

I have changed it.
For onHotKeys, I don't know what the api looks to make sense.
Like onHotKeys(key, handler, {modifiers: ['Ctrl', 'Shift']})?

@antfu
Copy link
Member

antfu commented Apr 4, 2021

onHotKeys

Haha, just an idea, no pressure on that. I might have some ideas of the implementation where I will draft it later.

@antfu antfu changed the title feat: add onKeyStroke function. feat(onKeyStroke): new functions Apr 4, 2021
@antfu antfu enabled auto-merge (squash) April 4, 2021 15:02
@antfu antfu merged commit 1f9c78c into vueuse:main Apr 4, 2021
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 this pull request may close these issues.

None yet

2 participants