Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hot-turkeys-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/core": patch
---

Fixes an edge case for placeholder values. Previously, when pressing `enter` on an empty prompt, placeholder values would be ignored. Now, placeholder values are treated as the prompt value.
5 changes: 5 additions & 0 deletions packages/core/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ export default class Prompt {
}

if (key?.name === 'return') {
if (!this.value && this.opts.placeholder) {
this.rl?.write(this.opts.placeholder);
this.emit('value', this.opts.placeholder);
}

if (this.opts.validate) {
const problem = this.opts.validate(this.value);
if (problem) {
Expand Down
6 changes: 3 additions & 3 deletions packages/prompts/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ describe.each(['true', 'false'])('prompts (isCI = %s)', (isCI) => {

input.emit('keypress', '', { name: 'return' });

await result;
const value = await result;

expect(output.buffer).toMatchSnapshot();
// TODO (43081j): uncomment this when #263 is fixed
// expect(value).toBe('bar');

expect(value).toBe('bar');
});

test('<tab> applies placeholder', async () => {
Expand Down