Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ exports[`prompt renderers > renders multiselect with cursor marker plus checkbox
Second line
› ◼ Beta
◻ Gamma
Press space to select, enter to submit

"
`;
Expand Down
21 changes: 12 additions & 9 deletions packages/prompts/src/multi-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
);
};
const required = opts.required ?? true;
const hint =
' ' +
color.reset(
color.dim(
`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(
color.bgWhite(color.inverse(' enter ')),
)} to submit`,
),
);

return new MultiSelectPrompt({
options: opts.options,
Expand All @@ -131,13 +140,7 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
cursorAt: opts.cursorAt,
validate(selected: Value[] | undefined) {
if (required && (selected === undefined || selected.length === 0)) {
return `Please select at least one option.\n${color.reset(
color.dim(
`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(
color.bgWhite(color.inverse(' enter ')),
)} to submit`,
),
)}`;
return `Please select at least one option.\n${hint}`;
}
return undefined;
},
Expand Down Expand Up @@ -221,7 +224,7 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
columnPadding: prefix.length,
rowPadding: titleLineCount + footerLineCount,
style: styleOption,
}).join(`\n${prefix}`)}\n${footer}\n`;
}).join(`\n${prefix}`)}\n${hint}\n${footer}\n`;
}
default: {
const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
Expand All @@ -236,7 +239,7 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
columnPadding: prefix.length,
rowPadding: titleLineCount + footerLineCount,
style: styleOption,
}).join(`\n${prefix}`)}\n${hasGuide ? color.blue(S_BAR_END) : ''}\n`;
}).join(`\n${prefix}`)}\n${hint}\n${hasGuide ? color.blue(S_BAR_END) : ''}\n`;
}
}
},
Expand Down
Loading