diff --git a/.changeset/hot-turkeys-knock.md b/.changeset/hot-turkeys-knock.md new file mode 100644 index 00000000..0c86eb91 --- /dev/null +++ b/.changeset/hot-turkeys-knock.md @@ -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. diff --git a/packages/core/src/prompts/prompt.ts b/packages/core/src/prompts/prompt.ts index c676d1a5..089e1dc8 100644 --- a/packages/core/src/prompts/prompt.ts +++ b/packages/core/src/prompts/prompt.ts @@ -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) { diff --git a/packages/prompts/src/index.test.ts b/packages/prompts/src/index.test.ts index aa2fab52..406bd933 100644 --- a/packages/prompts/src/index.test.ts +++ b/packages/prompts/src/index.test.ts @@ -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(' applies placeholder', async () => {