From f91d3238badfe374aefed015181323d647cd7804 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 15 Oct 2026 22:54:19 +0800 Subject: [PATCH 1/2] fix(prompts): preserve falsy autocomplete initial values --- .changeset/curly-mails-glow.md | 6 ++++++ packages/prompts/src/autocomplete.ts | 2 +- packages/prompts/test/autocomplete.test.ts | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .changeset/curly-mails-glow.md diff --git a/.changeset/curly-mails-glow.md b/.changeset/curly-mails-glow.md new file mode 100644 index 00000000..b8c2944f --- /dev/null +++ b/.changeset/curly-mails-glow.md @@ -0,0 +1,6 @@ +--- +"@clack/prompts": patch +"@clack/core": patch +--- + +Use an explicit undefined check when forwarding autocomplete initialValue so 0, false, and empty strings remain selectable instead of falling back to thefirst option. diff --git a/packages/prompts/src/autocomplete.ts b/packages/prompts/src/autocomplete.ts index f3dd1465..0cfc5165 100644 --- a/packages/prompts/src/autocomplete.ts +++ b/packages/prompts/src/autocomplete.ts @@ -129,7 +129,7 @@ export interface AutocompleteOptions extends AutocompleteSharedOptions(opts: AutocompleteOptions) => { const prompt = new AutocompletePrompt({ options: opts.options, - initialValue: opts.initialValue ? [opts.initialValue] : undefined, + initialValue: opts.initialValue !== undefined ? [opts.initialValue] : undefined, initialUserInput: opts.initialUserInput, placeholder: opts.placeholder, completeOnTab: opts.completeOnTab, diff --git a/packages/prompts/test/autocomplete.test.ts b/packages/prompts/test/autocomplete.test.ts index fe55444c..7351bab2 100644 --- a/packages/prompts/test/autocomplete.test.ts +++ b/packages/prompts/test/autocomplete.test.ts @@ -185,6 +185,24 @@ describe('autocomplete', () => { expect(output.buffer).toMatchSnapshot(); }); + test('supports falsy initialValue values', async () => { + for (const initialValue of [0, false, '']) { + const input = new MockReadable(); + const output = new MockWritable(); + const result = autocomplete({ + message: 'Select a value', + options: [{ value: 'other' }, { value: initialValue }], + initialValue, + input, + output, + }); + + input.emit('keypress', '', { name: 'return' }); + + expect(await result).toBe(initialValue); + } + }); + test('can be aborted by a signal', async () => { const controller = new AbortController(); const result = autocomplete({ From b9ca20f68e97188602bd39f23a9bc8b7113a71bb Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 16 Oct 2026 07:19:54 +0800 Subject: [PATCH 2/2] fix: update --- .changeset/curly-mails-glow.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/curly-mails-glow.md b/.changeset/curly-mails-glow.md index b8c2944f..4d2306a8 100644 --- a/.changeset/curly-mails-glow.md +++ b/.changeset/curly-mails-glow.md @@ -1,6 +1,5 @@ --- "@clack/prompts": patch -"@clack/core": patch --- -Use an explicit undefined check when forwarding autocomplete initialValue so 0, false, and empty strings remain selectable instead of falling back to thefirst option. +Use an explicit undefined check when forwarding autocomplete initialValue so 0, false, and empty strings remain selectable instead of falling back to the first option.