Skip to content

Commit 34a6020

Browse files
authored
Fix default clearing on input (#1161)
1 parent 94d3217 commit 34a6020

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

packages/inquirer/lib/prompts/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default class InputPrompt extends Base {
100100
*/
101101

102102
onKeypress() {
103-
this.state = 'touched';
103+
this.status = 'touched';
104104

105105
this.render();
106106
}

packages/inquirer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
},
5555
"devDependencies": {
5656
"chai": "^4.3.6",
57+
"chai-string": "^1.5.0",
5758
"chalk-pipe": "^5.1.2",
5859
"cmdify": "^0.0.4",
5960
"mocha": "^10.0.0",

packages/inquirer/test/specs/prompts/input.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { expect } from 'chai';
1+
import chai, { expect } from 'chai';
2+
import chaiString from 'chai-string';
23
import ReadlineStub from '../../helpers/readline.js';
34
import fixtures from '../../helpers/fixtures.js';
45

56
import Input from '../../../lib/prompts/input.js';
67

8+
chai.use(chaiString);
9+
710
describe('`input` prompt', () => {
811
beforeEach(function () {
912
this.fixture = { ...fixtures.input };
@@ -94,4 +97,24 @@ describe('`input` prompt', () => {
9497
done();
9598
}, 200);
9699
});
100+
101+
it('should clear default on input', function (done) {
102+
const defaultValue = 'default-string';
103+
const input = new Input(
104+
{
105+
...this.fixture,
106+
default: defaultValue,
107+
},
108+
this.rl
109+
);
110+
111+
input.run();
112+
113+
this.rl.line = 'inquirer';
114+
this.rl.input.emit('keypress');
115+
setTimeout(() => {
116+
expect(this.rl.output.__raw__).to.have.entriesCount(defaultValue, 1);
117+
done();
118+
}, 200);
119+
});
97120
});

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,11 @@ caniuse-lite@^1.0.30001332:
25322532
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001339.tgz#f9aece4ea8156071613b27791547ba0b33f176cf"
25332533
integrity sha512-Es8PiVqCe+uXdms0Gu5xP5PF2bxLR7OBp3wUzUnuO7OHzhOfCyg3hdiGWVPVxhiuniOzng+hTc1u3fEQ0TlkSQ==
25342534

2535+
chai-string@^1.5.0:
2536+
version "1.5.0"
2537+
resolved "https://registry.yarnpkg.com/chai-string/-/chai-string-1.5.0.tgz#0bdb2d8a5f1dbe90bc78ec493c1c1c180dd4d3d2"
2538+
integrity sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw==
2539+
25352540
chai@^4.3.6:
25362541
version "4.3.6"
25372542
resolved "https://registry.npmjs.org/chai/-/chai-4.3.6.tgz"

0 commit comments

Comments
 (0)