@@ -40,12 +40,15 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
4040 const next = isItem && ( options [ options . indexOf ( option ) + 1 ] ?? { group : true } ) ;
4141 const isLast = isItem && ( next as any ) . group === true ;
4242 const prefix = isItem ? ( selectableGroups ? `${ isLast ? S_BAR_END : S_BAR } ` : ' ' ) : '' ;
43- const spacingPrefix =
44- groupSpacing > 0 && ! isItem ? `\n${ color . cyan ( S_BAR ) } ` . repeat ( groupSpacing ) : '' ;
43+ let spacingPrefix = '' ;
44+ if ( groupSpacing > 0 && ! isItem ) {
45+ const spacingPrefixText = `\n${ color . cyan ( S_BAR ) } ` ;
46+ spacingPrefix = `${ spacingPrefixText . repeat ( groupSpacing - 1 ) } ${ spacingPrefixText } ` ;
47+ }
4548
4649 if ( state === 'active' ) {
47- return `${ spacingPrefix } ${ color . dim ( prefix ) } ${ color . cyan ( S_CHECKBOX_ACTIVE ) } ${ label } ${
48- option . hint ? color . dim ( `(${ option . hint } )` ) : ''
50+ return `${ spacingPrefix } ${ color . dim ( prefix ) } ${ color . cyan ( S_CHECKBOX_ACTIVE ) } ${ label } ${
51+ option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ''
4952 } `;
5053 }
5154 if ( state === 'group-active' ) {
@@ -56,16 +59,16 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
5659 }
5760 if ( state === 'selected' ) {
5861 const selectedCheckbox = isItem || selectableGroups ? color . green ( S_CHECKBOX_SELECTED ) : '' ;
59- return `${ spacingPrefix } ${ color . dim ( prefix ) } ${ selectedCheckbox } ${ color . dim ( label ) } ${
60- option . hint ? color . dim ( `(${ option . hint } )` ) : ''
62+ return `${ spacingPrefix } ${ color . dim ( prefix ) } ${ selectedCheckbox } ${ color . dim ( label ) } ${
63+ option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ''
6164 } `;
6265 }
6366 if ( state === 'cancelled' ) {
6467 return `${ color . strikethrough ( color . dim ( label ) ) } ` ;
6568 }
6669 if ( state === 'active-selected' ) {
67- return `${ spacingPrefix } ${ color . dim ( prefix ) } ${ color . green ( S_CHECKBOX_SELECTED ) } ${ label } ${
68- option . hint ? color . dim ( `(${ option . hint } )` ) : ''
70+ return `${ spacingPrefix } ${ color . dim ( prefix ) } ${ color . green ( S_CHECKBOX_SELECTED ) } ${ label } ${
71+ option . hint ? ` ${ color . dim ( `(${ option . hint } )` ) } ` : ''
6972 } `;
7073 }
7174 if ( state === 'submitted' ) {
@@ -101,10 +104,12 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
101104
102105 switch ( this . state ) {
103106 case 'submit' : {
104- return ` ${ title } ${ color . gray ( S_BAR ) } ${ this . options
107+ const selectedOptions = this . options
105108 . filter ( ( { value : optionValue } ) => value . includes ( optionValue ) )
106- . map ( ( option ) => opt ( option , 'submitted' ) )
107- . join ( color . dim ( ', ' ) ) } `;
109+ . map ( ( option ) => opt ( option , 'submitted' ) ) ;
110+ const optionsText =
111+ selectedOptions . length === 0 ? '' : ` ${ selectedOptions . join ( color . dim ( ', ' ) ) } ` ;
112+ return `${ title } ${ color . gray ( S_BAR ) } ${ optionsText } ` ;
108113 }
109114 case 'cancel' : {
110115 const label = this . options
@@ -146,7 +151,7 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
146151 . join ( `\n${ color . yellow ( S_BAR ) } ` ) } \n${ footer } \n`;
147152 }
148153 default : {
149- return ` ${ title } ${ color . cyan ( S_BAR ) } ${ this . options
154+ const optionsText = this . options
150155 . map ( ( option , i , options ) => {
151156 const selected =
152157 value . includes ( option . value ) ||
@@ -156,18 +161,26 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
156161 ! active &&
157162 typeof option . group === 'string' &&
158163 this . options [ this . cursor ] . value === option . group ;
164+ let optionText = '' ;
159165 if ( groupActive ) {
160- return opt ( option , selected ? 'group-active-selected' : 'group-active' , options ) ;
161- }
162- if ( active && selected ) {
163- return opt ( option , 'active-selected' , options ) ;
166+ optionText = opt (
167+ option ,
168+ selected ? 'group-active-selected' : 'group-active' ,
169+ options
170+ ) ;
171+ } else if ( active && selected ) {
172+ optionText = opt ( option , 'active-selected' , options ) ;
173+ } else if ( selected ) {
174+ optionText = opt ( option , 'selected' , options ) ;
175+ } else {
176+ optionText = opt ( option , active ? 'active' : 'inactive' , options ) ;
164177 }
165- if ( selected ) {
166- return opt ( option , 'selected' , options ) ;
167- }
168- return opt ( option , active ? 'active' : 'inactive' , options ) ;
178+ const prefix = i !== 0 && ! optionText . startsWith ( '\n' ) ? ' ' : '' ;
179+ return `${ prefix } ${ optionText } ` ;
169180 } )
170- . join ( `\n${ color . cyan ( S_BAR ) } ` ) } \n${ color . cyan ( S_BAR_END ) } \n`;
181+ . join ( `\n${ color . cyan ( S_BAR ) } ` ) ;
182+ const optionsPrefix = optionsText . startsWith ( '\n' ) ? '' : ' ' ;
183+ return `${ title } ${ color . cyan ( S_BAR ) } ${ optionsPrefix } ${ optionsText } \n${ color . cyan ( S_BAR_END ) } \n` ;
171184 }
172185 }
173186 } ,
0 commit comments