@@ -32,24 +32,44 @@ export type InternalSelectProps = {
32
32
_itemsMap : TItemsMap ;
33
33
} ;
34
34
35
- export type SelectProps <
36
- M extends true ,
37
- T = boolean extends M ? string : M extends true ? string [ ] : string ,
38
- > = Omit < PropsOf < 'div' > , 'onChange$' > & {
35
+ export type TMultiple < M > = M extends true ? string [ ] : string ;
36
+
37
+ /**
38
+ * Value sets an initial value for the select. If multiple is true, value is disabled
39
+ *
40
+ */
41
+ type TMultiValue =
42
+ | { multiple : true ; value ?: never }
43
+ | { multiple ?: false ; value ?: string } ;
44
+
45
+ type TStringOrArray =
46
+ | {
47
+ multiple ?: true ;
48
+ onChange$ ?: QRL < ( value : string [ ] ) => void > ;
49
+ }
50
+ | {
51
+ multiple ?: false ;
52
+ onChange$ ?: QRL < ( value : string ) => void > ;
53
+ } ;
54
+
55
+ export type SelectProps < M extends boolean = boolean > = Omit <
56
+ PropsOf < 'div' > ,
57
+ 'onChange$'
58
+ > & {
39
59
/** A signal that controls the current selected value (controlled). */
40
- 'bind:value' ?: T extends string ? Signal < T > : never ;
60
+ 'bind:value' ?: Signal < TMultiple < M > > ;
41
61
42
62
/** A signal that controls the current open state (controlled). */
43
63
'bind:open' ?: Signal < boolean > ;
44
64
45
65
// eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- 'bind:displayValue' ?: T extends string ? Signal < T > : never ;
66
+ 'bind:displayValue' ?: Signal < TMultiple < M > > ;
47
67
48
68
/**
49
69
* QRL handler that runs when a select value changes.
50
70
* @param value The new value as a string.
51
71
*/
52
- onChange$ ?: QRL < ( value : T ) => void > ;
72
+ onChange$ ?: QRL < ( value : TMultiple < M > ) => void > ;
53
73
/**
54
74
* QRL handler that runs when the listbox opens or closes.
55
75
* @param open The new state of the listbox.
@@ -87,18 +107,13 @@ export type SelectProps<
87
107
*/
88
108
multiple ?: M ;
89
109
90
- /**
91
- * Value sets an initial value for the select. If multiple is true, value is disabled
92
- *
93
- */
94
- value ?: M extends false ? string : never ;
95
-
96
110
invalid ?: boolean ;
97
- } ;
111
+ } & TMultiValue &
112
+ TStringOrArray ;
98
113
99
114
/* root component in select-inline.tsx */
100
- export const HSelectImpl = component$ (
101
- < M extends true , T > ( props : SelectProps < M , T > & InternalSelectProps ) => {
115
+ export const HSelectImpl = component$ < SelectProps < boolean > & InternalSelectProps > (
116
+ ( props : SelectProps < boolean > & InternalSelectProps ) => {
102
117
const {
103
118
_itemsMap,
104
119
_valuePropIndex : givenValuePropIndex ,
@@ -244,7 +259,7 @@ export const HSelectImpl = component$(
244
259
}
245
260
246
261
if ( onChange$ && selectedIndexSetSig . value . size > 0 ) {
247
- await onChange$ ( context . multiple ? ( values as T ) : ( values [ 0 ] as T ) ) ;
262
+ await onChange$ ( context . multiple ? values : values [ 0 ] ) ;
248
263
}
249
264
250
265
// sync the user's given signal when an option is selected
@@ -254,9 +269,9 @@ export const HSelectImpl = component$(
254
269
255
270
if ( currUserSigValues !== newUserSigValues ) {
256
271
if ( context . multiple ) {
257
- bindValueSig . value = values as T ;
272
+ bindValueSig . value = values ;
258
273
} else {
259
- bindValueSig . value = values [ 0 ] as T ;
274
+ bindValueSig . value = values [ 0 ] ;
260
275
}
261
276
}
262
277
}
@@ -266,8 +281,8 @@ export const HSelectImpl = component$(
266
281
// sync the user's given signal for the display value
267
282
if ( bindDisplayTextSig && context . currDisplayValueSig . value ) {
268
283
bindDisplayTextSig . value = context . multiple
269
- ? ( context . currDisplayValueSig . value as T )
270
- : ( context . currDisplayValueSig . value [ 0 ] as T ) ;
284
+ ? context . currDisplayValueSig . value
285
+ : context . currDisplayValueSig . value [ 0 ] ;
271
286
}
272
287
} ) ;
273
288
0 commit comments