Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to prefill input on autocomplete #414

Open
ianwalter opened this issue Mar 13, 2024 · 1 comment
Open

Ability to prefill input on autocomplete #414

ianwalter opened this issue Mar 13, 2024 · 1 comment

Comments

@ianwalter
Copy link
Contributor

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.

@ianwalter
Copy link
Contributor Author

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;
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant