Skip to content

Commit 8ead5d3

Browse files
authored
fix: do not pass initialValue down (#328)
1 parent f90f47d commit 8ead5d3

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

.changeset/sweet-deers-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/core": patch
3+
---
4+
5+
Avoid passing initial values to core when using auto complete prompt

packages/core/src/prompts/autocomplete.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ export default class AutocompletePrompt<T extends OptionLike> extends Prompt {
7979
}
8080

8181
constructor(opts: AutocompleteOptions<T>) {
82-
super(opts);
82+
super({
83+
...opts,
84+
initialValue: undefined,
85+
});
8386

8487
this.options = opts.options;
8588
this.filteredOptions = [...this.options];

packages/prompts/test/__snapshots__/autocomplete.test.ts.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,28 @@ exports[`autocomplete > shows strikethrough in cancel state 1`] = `
183183
"<cursor.show>",
184184
]
185185
`;
186+
187+
exports[`autocomplete > supports initialValue 1`] = `
188+
[
189+
"<cursor.hide>",
190+
"│
191+
◆ Select a fruit
192+
193+
│ Search: _
194+
│ ○ Apple
195+
│ ○ Banana
196+
│ ● Cherry
197+
│ ○ Grape
198+
│ ○ Orange
199+
│ ↑/↓ to select • Enter: confirm • Type: to search
200+
└",
201+
"<cursor.backward count=999><cursor.up count=10>",
202+
"<cursor.down count=1>",
203+
"<erase.down>",
204+
"◇ Select a fruit
205+
│ Cherry",
206+
"
207+
",
208+
"<cursor.show>",
209+
]
210+
`;

packages/prompts/test/autocomplete.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,19 @@ describe('autocomplete', () => {
120120
expect(typeof value === 'symbol').toBe(true);
121121
expect(output.buffer).toMatchSnapshot();
122122
});
123+
124+
test('supports initialValue', async () => {
125+
const result = autocomplete({
126+
message: 'Select a fruit',
127+
options: testOptions,
128+
initialValue: 'cherry',
129+
input,
130+
output,
131+
});
132+
133+
input.emit('keypress', '', { name: 'return' });
134+
const value = await result;
135+
expect(value).toBe('cherry');
136+
expect(output.buffer).toMatchSnapshot();
137+
});
123138
});

0 commit comments

Comments
 (0)