Skip to content

Commit

Permalink
fix: retain number prompt default
Browse files Browse the repository at this point in the history
  • Loading branch information
tjallingt committed Jun 15, 2021
1 parent c4a3c23 commit 2bc4808
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/inquirer/lib/prompts/base.js
Expand Up @@ -150,8 +150,12 @@ class Prompt {
this.opt.suffix +
chalk.reset(' ');

// Append the default if available, and if question isn't answered
if (this.opt.default != null && this.status !== 'answered') {
// Append the default if available, and if question isn't touched/answered
if (
this.opt.default != null &&
this.status !== 'touched' &&
this.status !== 'answered'
) {
// If default password is supplied, hide it
if (this.opt.type === 'password') {
message += chalk.italic.dim('[hidden] ');
Expand Down
5 changes: 1 addition & 4 deletions packages/inquirer/lib/prompts/input.js
Expand Up @@ -101,10 +101,7 @@ class InputPrompt extends Base {
*/

onKeypress() {
// If user press a key, just clear the default value
if (this.opt.default) {
this.opt.default = undefined;
}
this.state = 'touched';

this.render();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/inquirer/test/specs/prompts/number.js
Expand Up @@ -111,6 +111,7 @@ describe('`number` prompt', () => {
done();
});

this.rl.emit('line', '');
this.rl.input.emit('keypress', 'a', { name: 'a' });
this.rl.emit('line');
});
});

0 comments on commit 2bc4808

Please sign in to comment.