minutemailer / react-popup

React popup component
http://minutemailer.github.io/react-popup/
MIT License
208 stars 71 forks source link

Submit Prompt on Enter #36

Closed jaschaio closed 7 years ago

jaschaio commented 7 years ago

Hey there, I am trying to listen to a "keydown" event and submit the popup prompt upon it.

The problem is that if I create a plugin like on the Demo Site, I have no access to the buttonClick or handleButtonClicks methods of the Popup Parent Component.

Any idea how to solve this?

Thanks

tbleckert commented 7 years ago

Hi!

I'm working on a real way of handling key events but for now it's not possible like you said. The way I currently handles it is by global key events. Like this (using keymaster for simple code in the example):

import key from 'keymaster';

key('enter', () => {
    // Trigger the click event on the submit action btn. The class is probably different in your setup tho.
    document.querySelector('.mm-popup__btn--success').click();
});

You can use the events Popup.addShowListener and Popup.addCloseListener to setup and remove the key event.

This is of course not an ideal solution. When the new release is out, you will be able to do this:

{
    text: 'Submit btn text',
    className: 'submit',
    key: '⌘+s', // any keymaster keyword
    action: function (popup) {
        // do stuff
        popup.close();
    }
}
jaschaio commented 7 years ago

Thanks, while it's not an ideal solution it's a simple one I hadn't thinked of. Looking forward to the next release, thanks!

tbleckert commented 7 years ago

Great and thanks! I'll close this one for now since we have issue #3 for the keyboard events feature already