Reputation: 477
I'm trying to implement a Modal component with Semantic UI React.
It's a simple confirmation modal, the user can answer with Yes or No.
I want to add the option for the user to press Enter as an alternative way to say Yes (and close the modal).
I've started adding an extra Input component to my modal to listen onKeyPress and answer to it, but i don't like it because of the extra component.
So i created a listener for keydown event but something strange happened: when you try to close the modal by pressing Enter it seems like it triggers again and it actually does not close...
https://codesandbox.io/s/lrjrp7vxy7
can you help me? Thanks.
Upvotes: 1
Views: 1112
Reputation: 477
I've found that everything works if you listen to keyup instead keydown in the event listener.
If you think there are more elegant solutions, please comment this thread. Thanks.
Upvotes: 1