Skip to content

Commit

Permalink
feat(select): customize the display text for disabled text (#1201)
Browse files Browse the repository at this point in the history
* feat(select): customize display text of disabled option

* Update packages/select/src/index.mts

Co-authored-by: Simon Boudrias <admin@simonboudrias.com>

---------

Co-authored-by: Simon Boudrias <admin@simonboudrias.com>
  • Loading branch information
zonemeen and SBoudrias committed Mar 18, 2023
1 parent f908b73 commit 5b94c7e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/select/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import figures from 'figures';
import ansiEscapes from 'ansi-escapes';

type SelectConfig = AsyncPromptConfig & {
choices: { value: string; name?: string; description?: string; disabled?: boolean }[];
choices: {
value: string;
name?: string;
description?: string;
disabled?: boolean | string;
}[];
pageSize?: number;
};

Expand Down Expand Up @@ -79,7 +84,9 @@ export default createPrompt<string, SelectConfig>((config, done) => {
.map(({ name, value, disabled }, index) => {
const line = name || value;
if (disabled) {
return chalk.dim(`- ${line} (disabled)`);
return chalk.dim(
`- ${line} ${typeof disabled === 'string' ? disabled : '(disabled)'}`
);
}

if (index === cursorPosition) {
Expand Down

0 comments on commit 5b94c7e

Please sign in to comment.