Skip to content

Commit a7d365a

Browse files
fix(select): fix, proper placeholder, value prop, and selected option
1 parent a588b13 commit a7d365a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/kit-headless/src/components/select/select-inline.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type Opt = {
1414
*/
1515
export const Select: FunctionComponent<SelectProps> = (props) => {
1616
const { children: myChildren, ...rest } = props;
17-
let valuePropIndex = 0;
17+
let valuePropIndex = null;
1818
const childrenToProcess = (
1919
Array.isArray(myChildren) ? [...myChildren] : [myChildren]
2020
) as Array<JSXNode>;
@@ -74,7 +74,8 @@ export const Select: FunctionComponent<SelectProps> = (props) => {
7474
}
7575
}
7676
const isDisabledArr = opts.map((opt) => opt.isDisabled);
77-
if (isDisabledArr[valuePropIndex] === true) {
77+
78+
if (valuePropIndex !== null && isDisabledArr[valuePropIndex] === true) {
7879
valuePropIndex = isDisabledArr.findIndex((isDisabled) => isDisabled === false);
7980
if (valuePropIndex === -1) {
8081
throw new Error(

packages/kit-headless/src/components/select/select-value.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ export const SelectValue = component$((props: SelectValueProps) => {
1010
const context = useContext(SelectContextId);
1111
if (!context.options) return;
1212

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+
1418
return (
1519
<span data-value {...props}>
16-
{selectedOptStr ?? context.value ?? props.placeholder}
20+
{selectedOptStr}
1721
</span>
1822
);
1923
});

0 commit comments

Comments
 (0)