@@ -27,7 +27,8 @@ export interface SelectProps<T extends object> extends Omit<AriaSelectProps<T>,
27
27
28
28
interface SelectValueContext {
29
29
state : SelectState < unknown > ,
30
- valueProps : HTMLAttributes < HTMLElement >
30
+ valueProps : HTMLAttributes < HTMLElement > ,
31
+ placeholder ?: string
31
32
}
32
33
33
34
export const SelectContext = createContext < ContextValue < SelectProps < any > , HTMLDivElement > > ( null ) ;
@@ -81,9 +82,9 @@ function Select<T extends object>(props: SelectProps<T>, ref: ForwardedRef<HTMLD
81
82
return (
82
83
< Provider
83
84
values = { [
84
- [ InternalSelectContext , { state, valueProps} ] ,
85
+ [ InternalSelectContext , { state, valueProps, placeholder : props . placeholder } ] ,
85
86
[ LabelContext , { ...labelProps , ref : labelRef , elementType : 'span' } ] ,
86
- [ ButtonContext , { ...triggerProps , ref : buttonRef , isPressed : state . isOpen } ] ,
87
+ [ ButtonContext , { ...triggerProps , ref : buttonRef , isPressed : state . isOpen , children : state . selectedItem ?. textValue ?? props . placeholder } ] ,
87
88
[ PopoverContext , {
88
89
state,
89
90
triggerRef : buttonRef ,
@@ -131,7 +132,7 @@ export interface SelectValueRenderProps<T> {
131
132
export interface SelectValueProps < T extends object > extends Omit < HTMLAttributes < HTMLElement > , keyof RenderProps < unknown > > , RenderProps < SelectValueRenderProps < T > > { }
132
133
133
134
function SelectValue < T extends object > ( props : SelectValueProps < T > , ref : ForwardedRef < HTMLSpanElement > ) {
134
- let { state, valueProps} = useContext ( InternalSelectContext ) ! ;
135
+ let { state, valueProps, placeholder } = useContext ( InternalSelectContext ) ! ;
135
136
let rendered = state . selectedItem ?. rendered ;
136
137
if ( typeof rendered === 'function' ) {
137
138
// If the selected item has a function as a child, we need to call it to render to JSX.
@@ -151,7 +152,7 @@ function SelectValue<T extends object>(props: SelectValueProps<T>, ref: Forwarde
151
152
let renderProps = useRenderProps ( {
152
153
...props ,
153
154
// TODO: localize this.
154
- defaultChildren : rendered || 'Select an item' ,
155
+ defaultChildren : rendered || placeholder || 'Select an item' ,
155
156
defaultClassName : 'react-aria-SelectValue' ,
156
157
values : {
157
158
selectedItem : state . selectedItem ?. value as T ?? null ,
0 commit comments