Skip to content

Commit e85b846

Browse files
committed
fix: do not render checkboxes when selectableGroups:false
1 parent 19c7d86 commit e85b846

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/prompts/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ export interface GroupMultiSelectOptions<Value> {
465465
selectableGroups?: boolean;
466466
}
467467
export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) => {
468+
const { selectableGroups = true } = opts;
468469
const opt = (
469470
option: Option<Value>,
470471
state:
@@ -482,7 +483,7 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
482483
const isItem = typeof (option as any).group === 'string';
483484
const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true });
484485
const isLast = isItem && (next as any).group === true;
485-
const prefix = isItem ? `${isLast ? S_BAR_END : S_BAR} ` : '';
486+
const prefix = isItem ? (selectableGroups ? `${isLast ? S_BAR_END : S_BAR} ` : ' ') : '';
486487

487488
if (state === 'active') {
488489
return `${color.dim(prefix)}${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${
@@ -496,7 +497,8 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
496497
return `${prefix}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
497498
}
498499
if (state === 'selected') {
499-
return `${color.dim(prefix)}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
500+
const selectedCheckbox = isItem || selectableGroups ? color.green(S_CHECKBOX_SELECTED) : '';
501+
return `${color.dim(prefix)}${selectedCheckbox} ${color.dim(label)}`;
500502
}
501503
if (state === 'cancelled') {
502504
return `${color.strikethrough(color.dim(label))}`;
@@ -509,15 +511,16 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
509511
if (state === 'submitted') {
510512
return `${color.dim(label)}`;
511513
}
512-
return `${color.dim(prefix)}${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(label)}`;
514+
const unselectedCheckbox = isItem || selectableGroups ? color.dim(S_CHECKBOX_INACTIVE) : '';
515+
return `${color.dim(prefix)}${unselectedCheckbox} ${color.dim(label)}`;
513516
};
514517

515518
return new GroupMultiSelectPrompt({
516519
options: opts.options,
517520
initialValues: opts.initialValues,
518521
required: opts.required ?? true,
519522
cursorAt: opts.cursorAt,
520-
selectableGroups: opts.selectableGroups,
523+
selectableGroups,
521524
validate(selected: Value[]) {
522525
if (this.required && selected.length === 0)
523526
return `Please select at least one option.\n${color.reset(

0 commit comments

Comments
 (0)