Skip to content

Commit 5dfce8a

Browse files
jsparkdevnatemoo-re
andcommittedApr 8, 2025·
fix: use placeholder as value when input is empty (#263)
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
1 parent 11a5dc1 commit 5dfce8a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed
 

Diff for: ‎.changeset/hot-turkeys-knock.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/core": patch
3+
---
4+
5+
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 for: ‎packages/core/src/prompts/prompt.ts

+5
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ export default class Prompt {
205205
}
206206

207207
if (key?.name === 'return') {
208+
if (!this.value && this.opts.placeholder) {
209+
this.rl?.write(this.opts.placeholder);
210+
this.emit('value', this.opts.placeholder);
211+
}
212+
208213
if (this.opts.validate) {
209214
const problem = this.opts.validate(this.value);
210215
if (problem) {

Diff for: ‎packages/prompts/src/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ describe.each(['true', 'false'])('prompts (isCI = %s)', (isCI) => {
210210

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

213-
await result;
213+
const value = await result;
214214

215215
expect(output.buffer).toMatchSnapshot();
216-
// TODO (43081j): uncomment this when #263 is fixed
217-
// expect(value).toBe('bar');
216+
217+
expect(value).toBe('bar');
218218
});
219219

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

0 commit comments

Comments
 (0)
Please sign in to comment.