@@ -133,8 +133,8 @@ export const confirm = (opts: ConfirmOptions) => {
133
133
type Primitive = Readonly < string | boolean | number >
134
134
135
135
type Option < Value > = Value extends Primitive
136
- ? { value : Value ; label ?: string ; hint ?: string }
137
- : { value : Value ; label : string ; hint ?: string }
136
+ ? { value : Value ; label ?: string ; hint ?: string ; group ?: string | true }
137
+ : { value : Value ; label : string ; hint ?: string ; group ?: string | true }
138
138
139
139
export interface SelectOptions < Value > {
140
140
message : string
@@ -184,6 +184,7 @@ export const select = <Value>(opts: SelectOptions<Value>) => {
184
184
} ) . prompt ( ) as Promise < Value >
185
185
}
186
186
187
+ // allows for the use of a) b) c) etc. options.
187
188
export const selectKey = < Value extends string > ( opts : SelectOptions < Value > ) => {
188
189
const renderOption = (
189
190
option : Option < Value > ,
@@ -211,13 +212,12 @@ export const selectKey = <Value extends string>(opts: SelectOptions<Value>) => {
211
212
initialValue : opts . initialValue ,
212
213
render ( ) {
213
214
const title = `${ chalk . gray ( symbols . BAR ) } \n${ coloredSymbol ( this . state ) } ${ opts . message } \n`
215
+ const selectedOption = this . options . find ( ( opt : { value : string } ) => opt . value === this . value )
216
+ if ( ! selectedOption ) return
214
217
215
218
switch ( this . state ) {
216
219
case 'submit' : {
217
- return `${ title } ${ chalk . gray ( symbols . BAR ) } ${ renderOption (
218
- this . options . find ( ( opt ) => opt . value === this . value ) ! ,
219
- 'selected' ,
220
- ) } `
220
+ return `${ title } ${ chalk . gray ( symbols . BAR ) } ${ renderOption ( selectedOption , 'selected' ) } `
221
221
}
222
222
case 'cancel' :
223
223
return `${ title } ${ chalk . gray ( symbols . BAR ) } ${ renderOption ( this . options [ 0 ] , 'cancelled' ) } \n${ chalk . gray (
@@ -357,9 +357,9 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
357
357
options : Option < Value > [ ] = [ ] ,
358
358
) => {
359
359
const label = option . label ?? String ( option . value )
360
- const isItem = typeof ( option as any ) . group === 'string'
360
+ const isItem = typeof option . group === 'string'
361
361
const next = isItem && ( options [ options . indexOf ( option ) + 1 ] ?? { group : true } )
362
- const isLast = isItem && ( next as any ) . group === true
362
+ const isLast = isItem && next && next . group === true
363
363
const prefix = isItem ? `${ isLast ? symbols . BAR_END : symbols . BAR } ` : ''
364
364
365
365
if ( state === 'active' ) {
0 commit comments