File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -267,7 +267,10 @@ export interface SelectOptions<Value> {
267267}
268268
269269export const select = < Value > ( opts : SelectOptions < Value > ) => {
270- const opt = ( option : Option < Value > , state : 'inactive' | 'active' | 'selected' | 'cancelled' ) => {
270+ const opt = (
271+ option : Option < Value > ,
272+ state : 'inactive' | 'active' | 'selected' | 'cancelled'
273+ ) => {
271274 const label = option . label ?? String ( option . value ) ;
272275 switch ( state ) {
273276 case 'selected' :
@@ -414,14 +417,28 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
414417 required : opts . required ?? true ,
415418 cursorAt : opts . cursorAt ,
416419 validate ( selected : Value [ ] ) {
417- if ( this . required && selected . length === 0 )
420+ if ( this . required && selected . length === 0 ) {
418421 return `Please select at least one option.\n${ color . reset (
419422 color . dim (
420423 `Press ${ color . gray ( color . bgWhite ( color . inverse ( ' space ' ) ) ) } to select, ${ color . gray (
421424 color . bgWhite ( color . inverse ( ' enter ' ) )
422425 ) } to submit`
423426 )
424427 ) } `;
428+ }
429+ const disabledOptions = opts . options
430+ . map ( ( option ) => {
431+ if ( selected . includes ( option . value ) && option . disabled ) {
432+ return option . label ?? option . value ;
433+ }
434+ return undefined ;
435+ } )
436+ . filter ( Boolean ) ;
437+ if ( disabledOptions . length ) {
438+ return `${ disabledOptions . join ( ', ' ) } ${
439+ disabledOptions . length > 1 ? 'options are' : 'option is'
440+ } disabled.`;
441+ }
425442 } ,
426443 render ( ) {
427444 const title = `${ color . gray ( S_BAR ) } \n${ symbol ( this . state ) } ${ opts . message } \n` ;
You can’t perform that action at this time.
0 commit comments