@@ -254,8 +254,8 @@ export const multiselect = <Options extends Option<Value>[], Value extends Primi
254254 initialValue : opts . initialValue ,
255255 required : opts . required ?? true ,
256256 cursorAt : opts . cursorAt ,
257- validate ( value ) {
258- if ( this . required && value . length === 0 )
257+ validate ( selected : Value [ ] ) {
258+ if ( this . required && selected . length === 0 )
259259 return `Please select at least one option.\n${ color . reset (
260260 color . dim (
261261 `Press ${ color . gray ( color . bgWhite ( color . inverse ( ' space ' ) ) ) } to select, ${ color . gray (
@@ -269,13 +269,15 @@ export const multiselect = <Options extends Option<Value>[], Value extends Primi
269269
270270 switch ( this . state ) {
271271 case 'submit' : {
272- return `${ title } ${ color . gray ( S_BAR ) } ${ this . value
273- . map ( ( option : Option < Value > ) => opt ( option , 'submitted' ) )
272+ return `${ title } ${ color . gray ( S_BAR ) } ${ this . options
273+ . filter ( ( { value } ) => this . value . includes ( value ) )
274+ . map ( ( option ) => opt ( option , 'submitted' ) )
274275 . join ( color . dim ( ', ' ) ) } `;
275276 }
276277 case 'cancel' : {
277- const label = this . value
278- . map ( ( option : Option < Value > ) => opt ( option , 'cancelled' ) )
278+ const label = this . options
279+ . filter ( ( { value } ) => this . value . includes ( value ) )
280+ . map ( ( option ) => opt ( option , 'cancelled' ) )
279281 . join ( color . dim ( ', ' ) ) ;
280282 return `${ title } ${ color . gray ( S_BAR ) } ${
281283 label . trim ( ) ? `${ label } \n${ color . gray ( S_BAR ) } ` : ''
@@ -290,9 +292,7 @@ export const multiselect = <Options extends Option<Value>[], Value extends Primi
290292 . join ( '\n' ) ;
291293 return `${ title } ${ color . yellow ( S_BAR ) } ${ this . options
292294 . map ( ( option , i ) => {
293- const selected = this . value . some (
294- ( { value } : Option < Value > ) => value === option . value
295- ) ;
295+ const selected = this . value . includes ( option . value ) ;
296296 const active = i === this . cursor ;
297297 if ( active && selected ) {
298298 return opt ( option , 'active-selected' ) ;
@@ -307,9 +307,7 @@ export const multiselect = <Options extends Option<Value>[], Value extends Primi
307307 default : {
308308 return `${ title } ${ color . cyan ( S_BAR ) } ${ this . options
309309 . map ( ( option , i ) => {
310- const selected = this . value . some (
311- ( { value } : Option < Value > ) => value === option . value
312- ) ;
310+ const selected = this . value . includes ( option . value ) ;
313311 const active = i === this . cursor ;
314312 if ( active && selected ) {
315313 return opt ( option , 'active-selected' ) ;
0 commit comments