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

Feat: @inquirer/prompts checkbox support for different name when selected

Open puco opened this issue 11 months ago • 2 comments

When using checkbox I would like to show more information in the name when a user selects an option. This information is quite expensive to retrieve, so I would only want to do it on selection. The feature should also support Promises to update the name of the Choice. Or this can be solved using events, which also could be exposed.

usage proposal:


const choices = await checkbox(
  message: "Select modules",
  choices: choice
    .map(({ name, value, key }) => ({
      name
      value,
      onChecked: async () => ({ name: `${name} - ${await getData(key)}` })
    }))

puco avatar Jan 16 '25 10:01 puco

I'm also willing to provide a PR, but would like to know how the API should look like for it.

puco avatar Jan 16 '25 10:01 puco

Hi, thanks for reaching out!

This should be implemented within the theme options of the checkbox prompt.

For performance & simplicity reason, I'd prefer all-in-all not to expose an async interface. That'll also just be a UX headache to manage.

SBoudrias avatar Jan 16 '25 20:01 SBoudrias

Hi 👋 I’d like to work on this issue as my first contribution. Just to confirm, the idea is to support a different label when a checkbox is selected (e.g. checkedName) and handle this within the theme options, correct?

Sakthieswaran-tech avatar Sep 14 '25 02:09 Sakthieswaran-tech

Hey @Sakthieswaran-tech, that's roughly right. Not sure on the exact API, I think I'd implement it somewhat similarly to the message theme option; with 2 parameters (choice, status: checked | unchecked | disabled) and consolidate the theming functions (like we should review if we still need disabledChoice after that change)

SBoudrias avatar Sep 14 '25 13:09 SBoudrias

Thanks a lot for the clarification I understand now — the idea is to add a theming hook for checkboxes similar to the message theme option, with a function like theme.checkbox(choice, status) where status can be checked | unchecked | disabled. I’ll first go through how the message theme option is implemented in the codebase, then draft an API plan for checkbox before starting the implementation. I’ll share the proposal here for confirmation before opening a PR.

Sakthieswaran-tech avatar Sep 14 '25 17:09 Sakthieswaran-tech