-
Notifications
You must be signed in to change notification settings - Fork 333
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
Dismiss Modal with Escape Keypress #357
Comments
I quite agree with this feature, this is a very constructive suggestion. 👍 I have the following views on this function:
Feel free to leave me any thoughts or updates. |
Thanks for being so receptive. I'll review the contributing guidelines and see if I can implement it tomorrow. I actually have written the If the code for the hook looks good and I have the time this week, I can take a stab at modifying components like modal to add the hook and the Should we start a list somewhere for the components that should implement the hook? Sorry if I'm a bit scattered, I haven't contributed to any projects before! Thanks again. |
@unix So I've implemented https://github.com/nonissue/react/tree/feat/use-key-press PR on my repo so you can easily view the changes: |
@nonissue Thank you for your amazing work!
1. I know I can get the trigger of handler through // Sometimes users need to use Event, we should not discard this information.
const handler = event => alert('down')
useKeyPress('Escape', handler) 2. Use useKeyPress('Escape', handler, {
type: 'keyup', // 'keydown' 'keyup'
})
// listen to two actions at the same time
useKeyPress(['Enter', 'Escape'], handler)
// Listen combo action
// All keys are pressed at the same time to trigger
useKeyPress(['Shift', 'Escape'], handler, { combo: true })
type Options = {
...
}
UseKeyPress = (key: string, handler: Function, options: Options) => void
useKeyPress('Enter', handler, {
element: SomeRef.current,
}) Besides, about the style of the code, �I suggest that some comments can be reduced. Add comments only for special scenarios or dirty logic, good naming and logic itself are very readable. These are my personal suggestions, I didn't write the code, so the ideas may not be accurate, I'd like to hear from you. |
Thanks for the feedback! The comments were only meant to be temporary, I didn't intend to merge this as it is, I just created the PR so you could more easily see the changes. I agree with:
I'm not so sure about:
I'll push what I've done tonight to the branch on my repo (definitely not finished) so you can have a look. I may not have time to work on things tomorrow, but should be able to spend some time on this later in the week. |
@nonissue I'm glad to see you're following up on this, I agree with you, the last three features you mentioned actually don't use scenarios, and we really don't have to think about them too early. It's a good choice for us to implement hook first in a simpler way, if there is a similar demand in the future, we can follow up and solve it. (we can discuss these complex features in a later release, keep it easy, please don't have too much burden.) |
@nonissue Are there any updates here? |
Would be good to have this hook available, currently there are some accessibility problems with some components (select, toggle, slider), that only can be solve with a hook like this @nonissue do you think you will have time to finish this? I can help you if you want |
Now we have done this by adding |
Response to keyboard events has now been added to the modal internals as well. (added |
Feature request 🚀
Expected
Examples
Misc
useKeyPress
hook so the functionality can be used elsewhere. Should I open a second issue for this suggestion?I may be able to tackle this, but just started playing with the project today, and so I'll look things over and read the contributing guide, and update this issue if I feel capable.
The text was updated successfully, but these errors were encountered: