terkelg/prompts

Ability to prefill input on autocomplete

ianwalter opened this issue · 1 comments

Is your feature request related to a problem?

I know you can supply an "initial" value to autocomplete but that has to match an option. What I want is the ability to supply an initial value of the input so that the options can be filtered immediately on first render. The use case is using this with a git cli where the user can submit a keyword to filter branches and so they would be presented with relevant branches instead of all of the git branches (hundreds of options).

Describe the solution you'd like

An option like initialInput or prefill where you could specify how the options are initially filtered and it would show up in the input automatically on first render.

Describe alternatives you've considered

I can't really think of a workaround or alternative solution for this.

Additional context

None.

Looks like I worked around this but pretty hacky:

{
  async suggest(input, choices) {
    if (!input && branch && !initialized) {
      input = branch;
    }
    return choices.filter(i => i.title.toLowerCase().includes(input.toLowerCase()))
  },
  onRender() {
    if (!this.input && branch && !initialized) {
      this.input = branch;
      this.cursor = branch.length;
    }
    initialized = true;
  },
}