-
-
Notifications
You must be signed in to change notification settings - Fork 314
Description
Is your feature request related to a problem?
If you provide an initial selection for the autocomplete prompt, and you try to type, the initial index is used when you are searching. In my case (and probably most others?), this is undesirable. I am already typing and just want the sorted list to select first option. I only want intial when this.select = ''. If it is not empty, then it should behave as if I did not provide an initial.
Here is a motivating example where I have implemented this functionality:
let lastInput = '';
const answers = await prompts([
{
type: 'autocomplete',
name: 'things',
choices: getChoices(),
message: 'Select thing',
initial: lastDeploy,
// @ts-ignore: Improperly typed from lib
onRender() {
const prompt = (this as unknown) as Record<string, unknown>;
if (prompt['input'] === '') {
prompt['select'] = prompt['initial'];
} else if (prompt['input'] !== lastInput) {
prompt['select'] = 0;
}
lastInput = prompt['input'] as string;
},
},
]);Describe the solution you'd like
My jerry-rigged in solution works well, but I would like to know if other users are desiring this feature and if I or someone could make a pr.
Describe alternatives you've considered
I can continue using my jerry-rig solution, for which my team will judge me.
Additional context
Example:
intial = 'xylophone'
things = ['apple', 'base', 'baseball', 'basketball', 'xylophone']
- inital prompt has xylophone selected
- I type 'b'
- prompt now has 'basketball' selected 😭
- I type in 'base', 'baseball' now selected!! 😭
- I must arrow up to get correct option
This issue is hard to notice, because if you have initial of 'apple' or 'base', it will behave as desired.