Skip to content

Commit 58de622

Browse files
authored
fixes #1025 rawlist stops handling arrow keys after bad input (#1026)
Co-authored-by: Doug Owings <[email protected]>
1 parent 44ba021 commit 58de622

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/inquirer/lib/prompts/rawlist.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ class RawListPrompt extends Base {
7373
validation.success.forEach(this.onEnd.bind(this));
7474
validation.error.forEach(this.onError.bind(this));
7575

76-
events.normalizedUpKey.pipe(takeUntil(events.line)).forEach(this.onUpKey.bind(this));
76+
events.normalizedUpKey
77+
.pipe(takeUntil(validation.success))
78+
.forEach(this.onUpKey.bind(this));
7779
events.normalizedDownKey
78-
.pipe(takeUntil(events.line))
80+
.pipe(takeUntil(validation.success))
7981
.forEach(this.onDownKey.bind(this));
8082
events.keypress
8183
.pipe(takeUntil(validation.success))

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

+16
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ describe('`rawlist` prompt', () => {
110110
this.rl.emit('line', this.rl.line);
111111
});
112112

113+
it('should allow for arrow navigation after invalid input', function (done) {
114+
this.rawlist
115+
.run()
116+
.then((answer) => {
117+
expect(answer).to.equal('bar');
118+
done();
119+
})
120+
.catch(done);
121+
122+
this.rl.emit('line', 'blah');
123+
this.rl.input.emit('keypress', '', { name: 'down' });
124+
this.rl.input.emit('keypress', '', { name: 'down' });
125+
this.rl.input.emit('keypress', '', { name: 'up' });
126+
this.rl.emit('line', this.rl.line);
127+
});
128+
113129
describe('going out of boundaries', () => {
114130
beforeEach(function () {
115131
this.pressKey = function (dir, times) {

0 commit comments

Comments
 (0)