Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Feature request: Native filter API for select

Open shinebayar-g opened this issue 2 years ago • 2 comments

Hi, just trying out the new @inquirer/prompts package. Looks much more easy to use. :clap:

I wish there was a native support for filtering values based on typed characters? I found this package was mentioned on previous issues https://github.com/mokkabonna/inquirer-autocomplete-prompt, but wouldn't it make sense to implement this in @inquirer/select?

const answer = await select({
  message: 'Select a package manager',
  choices: [
    {
      name: 'npm',
      value: 'npm',
      description: 'npm is the most popular package manager',
    },
    {
      name: 'yarn',
      value: 'yarn',
      description: 'yarn is an awesome package manager',
    },
    {
      name: 'jspm',
      value: 'jspm',
      disabled: true,
    },
    {
      name: 'pnpm',
      value: 'pnpm',
      disabled: '(pnpm is not available)',
    },
  ],
});

If user starts typing out some letters, list of choices would be filtered out or highlighted. image

Follow up suggestion. If there was an another selection like Other in the list, user could select that option and type out their input.

shinebayar-g avatar May 04 '23 01:05 shinebayar-g

Hey! I'm not really open to add a Other type API; I think it might complicate the prompt for a not super common use case (an "other" option can be a follow-up input prompt.)

But I think searching by typing would be a nice feature to add. I would try to keep the UX as close to the native <select> component on the web as possible.

SBoudrias avatar May 04 '23 20:05 SBoudrias

Being able to filter long lists would be great! Right now you can scroll alphabetically, but being able to type to filter (and then select) would be an awesome prompt.

xavdid avatar Sep 18 '23 05:09 xavdid

🙏 This requirement is very common; hope to continue following up.

anran758 avatar Feb 28 '24 11:02 anran758

If anyone wants to give #1367 a try, it'd be great to get your feedback!

SBoudrias avatar Mar 04 '24 13:03 SBoudrias

Hey @SBoudrias how can I incorporate that example to my current select ? I am trying to filter out as people type options.

bombillazo avatar Apr 12 '24 13:04 bombillazo

Hey @bombillazo, nothing to do it is a default behavior. As long as you use the new Inquirer (#1214 - the @inquirer/*** packages), and a recent enough version.

SBoudrias avatar Apr 12 '24 13:04 SBoudrias