Inquirer.js
Inquirer.js copied to clipboard
Prompts version of Checkbox no longer supports `loop`
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?
Digging into the code a little, it looks like the new paginator is always infinite, so this would apply to lists as well.
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.
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.
I'd love to pick this up!
Thanks @artfuldev ! Let me know if you need support at any point.
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:
- add
loop: falsetocheckbox. - pull up
paginatorfromcheckboxintocore - add
loop: falseto select` - add
loop: falsetorawlist
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?
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.
Oops, I seem to have completely missed that! Thank you so much for the direction. That helps a lot!