44 SelectItemProps as KSelectItemProps ,
55 SelectRootProps as KSelectRootProps ,
66} from "@kobalte/core/select" ;
7- import { Accessor , JSX , JSXElement , ParentProps , Show , splitProps } from "solid-js" ;
7+ import { Accessor , For , JSX , JSXElement , ParentProps , Show , splitProps } from "solid-js" ;
88import { CheckIcon } from "../../icons/CheckIcon" ;
99import { SelectorIcon } from "../../icons/SelectorIcon" ;
1010import { mergeClasses } from "../../utils/css" ;
@@ -19,7 +19,7 @@ import * as styles from "./Select.css";
1919import { SlotProp } from "../../utils/component" ;
2020
2121// TODO: add to base field slot that respect the BaseFieldProps signature?
22- type SelectSlot = "root" | "input" | "label" | "errorLabel" ;
22+ type SelectSlot = "root" | "input" | "label" | "errorLabel" | "itemValue" ;
2323
2424export type SelectProps < Option , OptGroup = never > = KSelectRootProps <
2525 Option ,
@@ -33,6 +33,7 @@ export type SelectProps<Option, OptGroup = never> = KSelectRootProps<
3333} & FieldWithErrorMessageSupport & {
3434 itemLabel ?: ( item : Option ) => JSXElement ;
3535 valueComponent ?: ( state : Accessor < Option > ) => JSXElement ;
36+ valueComponentMultiple ?: ( state : Accessor < Option [ ] > ) => JSXElement ;
3637} & SlotProp < SelectSlot > ;
3738
3839function SelectContent ( props : ParentProps < KSelectContentProps > ) {
@@ -76,8 +77,8 @@ export function Select<Option, OptGroup = never>(props: ParentProps<SelectProps<
7677
7778 const labelProps = createFieldLabelProps < "span" > ( {
7879 get class ( ) {
79- return props . slotClasses ?. label
80- }
80+ return props . slotClasses ?. label ;
81+ } ,
8182 } ) ;
8283
8384 const descriptionProps = createFieldMessageProps ( { } ) ;
@@ -101,13 +102,30 @@ export function Select<Option, OptGroup = never>(props: ParentProps<SelectProps<
101102 aria-label = { local [ "aria-label" ] }
102103 class = { mergeClasses ( baseFieldProps . baseStyle ( ) , styles . selectField ) }
103104 >
104- < KSelect . Value < Option > >
105+ < KSelect . Value < Option > class = { others . slotClasses ?. itemValue } >
105106 { state => {
106- const value = state . selectedOption ( ) ;
107- if ( ! value ) return null ;
108- return local . valueComponent
109- ? local . valueComponent ( state . selectedOption )
110- : ( state . selectedOption ( ) as string ) ;
107+
108+ return (
109+ < Show
110+ fallback = { ( ( ) => {
111+ const value = state . selectedOption ( ) ;
112+ if ( ! value ) return null ;
113+ return local . valueComponent
114+ ? local . valueComponent ( state . selectedOption )
115+ : ( state . selectedOption ( ) as string ) ;
116+ } ) ( ) }
117+ when = { props . multiple } >
118+ < Show
119+ fallback = { state . selectedOptions ( ) . join ( ", " ) }
120+ when = { props . valueComponentMultiple } >
121+ { callback => (
122+ < >
123+ { callback ( ) ( state . selectedOptions ) }
124+ </ >
125+ ) }
126+ </ Show >
127+ </ Show >
128+ ) ;
111129 } }
112130 </ KSelect . Value >
113131 < KSelect . Icon >
0 commit comments