@@ -32,24 +32,44 @@ export type InternalSelectProps = {
3232 _itemsMap : TItemsMap ;
3333} ;
3434
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+ > & {
3959 /** A signal that controls the current selected value (controlled). */
40- 'bind:value' ?: T extends string ? Signal < T > : never ;
60+ 'bind:value' ?: Signal < TMultiple < M > > ;
4161
4262 /** A signal that controls the current open state (controlled). */
4363 'bind:open' ?: Signal < boolean > ;
4464
4565 // eslint-disable-next-line @typescript-eslint/no-explicit-any
46- 'bind:displayValue' ?: T extends string ? Signal < T > : never ;
66+ 'bind:displayValue' ?: Signal < TMultiple < M > > ;
4767
4868 /**
4969 * QRL handler that runs when a select value changes.
5070 * @param value The new value as a string.
5171 */
52- onChange$ ?: QRL < ( value : T ) => void > ;
72+ onChange$ ?: QRL < ( value : TMultiple < M > ) => void > ;
5373 /**
5474 * QRL handler that runs when the listbox opens or closes.
5575 * @param open The new state of the listbox.
@@ -87,18 +107,13 @@ export type SelectProps<
87107 */
88108 multiple ?: M ;
89109
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-
96110 invalid ?: boolean ;
97- } ;
111+ } & TMultiValue &
112+ TStringOrArray ;
98113
99114/* 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 ) => {
102117 const {
103118 _itemsMap,
104119 _valuePropIndex : givenValuePropIndex ,
@@ -244,7 +259,7 @@ export const HSelectImpl = component$(
244259 }
245260
246261 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 ] ) ;
248263 }
249264
250265 // sync the user's given signal when an option is selected
@@ -254,9 +269,9 @@ export const HSelectImpl = component$(
254269
255270 if ( currUserSigValues !== newUserSigValues ) {
256271 if ( context . multiple ) {
257- bindValueSig . value = values as T ;
272+ bindValueSig . value = values ;
258273 } else {
259- bindValueSig . value = values [ 0 ] as T ;
274+ bindValueSig . value = values [ 0 ] ;
260275 }
261276 }
262277 }
@@ -266,8 +281,8 @@ export const HSelectImpl = component$(
266281 // sync the user's given signal for the display value
267282 if ( bindDisplayTextSig && context . currDisplayValueSig . value ) {
268283 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 ] ;
271286 }
272287 } ) ;
273288
0 commit comments