Skip to content

Commit

Permalink
Catch the enter keypress event before submit
Browse files Browse the repository at this point in the history
Fixes #54
  • Loading branch information
p-sam committed Jan 24, 2020
1 parent efb3cba commit ca0c3ad
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/page/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ docReady(() => {
}

dataEl.addEventListener('keyup', e => {
if (e.key === 'Enter') {
promptSubmit();
}

if (e.key === 'Escape') {
promptCancel();
}
});

dataEl.addEventListener('keypress', e => {
if (e.key === 'Enter') {
e.preventDefault();
promptSubmit();
}
});
} else if (promptOptions.type === 'select') {
dataEl = document.createElement('select');
let optionEl;
Expand Down

4 comments on commit ca0c3ad

@Fraasi
Copy link
Contributor

@Fraasi Fraasi commented on ca0c3ad Jan 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keypress fixed the enter problem but broke escape. Keydown works for both.

@p-sam
Copy link
Owner Author

@p-sam p-sam commented on ca0c3ad Jan 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as you can see, I now listen for the keypress event for Enter, and the keyup event for Escape. Did you try the fix? (What electron ver, os, etc)

@Fraasi
Copy link
Contributor

@Fraasi Fraasi commented on ca0c3ad Jan 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, didn't see it the first time. Tested prompt 1.5.1 on win10, Node.js 12.4.0, Chromium 76.0.3809.146, and Electron 6.1.7.
Everything works ok again.

@p-sam
Copy link
Owner Author

@p-sam p-sam commented on ca0c3ad Jan 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing, it's now in the v1.5.1 release, and published on npm

Please sign in to comment.