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

Prompts version of Checkbox no longer supports `loop`

Open jftanner opened this issue 2 years ago • 8 comments

With the old inquirer.prompt(questions) approach, I tended to set loop: false on checkbox prompts because it gave a better UX for long lists.

Unfortunately, that that no longer seems to work with @inquirer/prompts. I notice it's not in the documentation either.

Is there any chance of getting that functionality back? Or was it removed for a reason?

jftanner avatar Aug 17 '23 17:08 jftanner

Digging into the code a little, it looks like the new paginator is always infinite, so this would apply to lists as well.

jftanner avatar Aug 17 '23 17:08 jftanner

Happy to get this feature back in. Not sure when I'll get to it, so let me know if you end up working on a PR.

SBoudrias avatar Aug 17 '23 20:08 SBoudrias

I would love to contribute but, unfortunately, I just don't foresee having the time. :/ If I do, I'll let you know!

Fortunately, it's not critical.

jftanner avatar Aug 17 '23 21:08 jftanner

I'd love to pick this up!

artfuldev avatar Aug 25 '23 01:08 artfuldev

Thanks @artfuldev ! Let me know if you need support at any point.

SBoudrias avatar Aug 25 '23 13:08 SBoudrias

Hi,

I've looked at the code, and from what I understand, in packages/inquirer, we use a paginator across 3 prompts, list, checkbox, and rawlist. list is now select in the latest set of packages, and we have the same 2 other prompts. Please let me know if I've covered everything.

I'm thinking of adding something similar to a paginator that will end up being used by all 3, along with a loop: false property as part of the config for these prompts. I could add the paginator into the core, so it is available for these 3 prompts, in addition to any other custom prompts (seems like a useful functionality). We could do this incrementally in a set of PRs:

  1. add loop: false to checkbox.
  2. pull up paginator from checkbox into core
  3. add loop: false to select`
  4. add loop: false to rawlist

Let me know what you prefer: we could do 1 or several PRs, or scope down to just loop: false in checkbox.

In addition, I think the expand prompt also works similar to a rawlist - and may also want to make use of the paginator? I'm not entirely sure about this and would love to know what you think. I can't find examples in the expand prompts or any tests to show they use loop even though it feels like they could. I think the expanded expand prompt is exactly like a rawlist, and probably can be simplified to just use a raw list internally. Please let me know what you think. We could do a separate set of PRs for this if needed

Lastly, do you mind assigning the issue to me?

artfuldev avatar Aug 25 '23 15:08 artfuldev

Hey @artfuldev, I assigned the issue to you.

There's a paginator in the new implementation, but it's been rewritten as a hook here https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/src/index.mts#L179-L219

So the idea would be to add the loop: false support there.

I'd ignore the pagination for rawlist & expand prompts (at least for now.) I didn't implement pagination in either in the new versions as it didn't seem necessary (and since those 2 prompts do not react to arrow keys, it just didn't seem to make sense to have pagination to start with.) So I'd say just focus on modifying the pagination hook and select/checkbox.

Adding tests for that new feature (I mainly care about tests in select/checkbox) would be great too to make sure it doesn't break in the future.

SBoudrias avatar Aug 27 '23 17:08 SBoudrias

Oops, I seem to have completely missed that! Thank you so much for the direction. That helps a lot!

artfuldev avatar Aug 27 '23 20:08 artfuldev