File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
packages/kit-headless/src/components/select Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export type Opt = {
14
14
*/
15
15
export const Select : FunctionComponent < SelectProps > = ( props ) => {
16
16
const { children : myChildren , ...rest } = props ;
17
- let valuePropIndex = 0 ;
17
+ let valuePropIndex = null ;
18
18
const childrenToProcess = (
19
19
Array . isArray ( myChildren ) ? [ ...myChildren ] : [ myChildren ]
20
20
) as Array < JSXNode > ;
@@ -74,7 +74,8 @@ export const Select: FunctionComponent<SelectProps> = (props) => {
74
74
}
75
75
}
76
76
const isDisabledArr = opts . map ( ( opt ) => opt . isDisabled ) ;
77
- if ( isDisabledArr [ valuePropIndex ] === true ) {
77
+
78
+ if ( valuePropIndex !== null && isDisabledArr [ valuePropIndex ] === true ) {
78
79
valuePropIndex = isDisabledArr . findIndex ( ( isDisabled ) => isDisabled === false ) ;
79
80
if ( valuePropIndex === - 1 ) {
80
81
throw new Error (
Original file line number Diff line number Diff line change @@ -10,10 +10,14 @@ export const SelectValue = component$((props: SelectValueProps) => {
10
10
const context = useContext ( SelectContextId ) ;
11
11
if ( ! context . options ) return ;
12
12
13
- const selectedOptStr = context . options [ context . selectedIndexSig . value ! ] . value ;
13
+ const selectedOptStr =
14
+ context . selectedIndexSig . value !== null
15
+ ? context . options [ context . selectedIndexSig . value ] . value
16
+ : props . placeholder ;
17
+
14
18
return (
15
19
< span data-value { ...props } >
16
- { selectedOptStr ?? context . value ?? props . placeholder }
20
+ { selectedOptStr }
17
21
</ span >
18
22
) ;
19
23
} ) ;
You can’t perform that action at this time.
0 commit comments