13
13
import { AriaSelectProps , HiddenSelect , useFocusRing , useListFormatter , useLocalizedStringFormatter , useSelect } from 'react-aria' ;
14
14
import { ButtonContext } from './Button' ;
15
15
import { Collection , Node , SelectState , useSelectState } from 'react-stately' ;
16
- import { CollectionBuilder } from '@react-aria/collections' ;
16
+ import { CollectionBuilder , createHideableComponent } from '@react-aria/collections' ;
17
17
import { ContextValue , Provider , RACValidation , removeDataAttributes , RenderProps , SlotProps , useContextProps , useRenderProps , useSlot , useSlottedContext } from './utils' ;
18
18
import { FieldErrorContext } from './FieldError' ;
19
19
import { filterDOMProps , mergeProps , useResizeObserver } from '@react-aria/utils' ;
@@ -238,7 +238,9 @@ export interface SelectValueRenderProps<T> {
238
238
/** The object values of the currently selected items. */
239
239
selectedItems : ( T | null ) [ ] ,
240
240
/** The textValue of the currently selected items. */
241
- selectedText : string
241
+ selectedText : string ,
242
+ /** The state of the select. */
243
+ state : SelectState < T , 'single' | 'multiple' >
242
244
}
243
245
244
246
export interface SelectValueProps < T extends object > extends Omit < HTMLAttributes < HTMLElement > , keyof RenderProps < unknown > > , RenderProps < SelectValueRenderProps < T > > { }
@@ -249,9 +251,9 @@ export const SelectValueContext = createContext<ContextValue<SelectValueProps<an
249
251
* SelectValue renders the current value of a Select, or a placeholder if no value is selected.
250
252
* It is usually placed within the button element.
251
253
*/
252
- export const SelectValue = /*#__PURE__*/ ( forwardRef as forwardRefType ) ( function SelectValue < T extends object > ( props : SelectValueProps < T > , ref : ForwardedRef < HTMLSpanElement > ) {
254
+ export const SelectValue = /*#__PURE__*/ createHideableComponent ( function SelectValue < T extends object > ( props : SelectValueProps < T > , ref : ForwardedRef < HTMLSpanElement > ) {
253
255
[ props , ref ] = useContextProps ( props , ref , SelectValueContext ) ;
254
- let state = useContext ( SelectStateContext ) ! ;
256
+ let state = useContext ( SelectStateContext ) ! as SelectState < T , 'single' | 'multiple' > ;
255
257
let { placeholder} = useSlottedContext ( SelectContext ) ! ;
256
258
let rendered = state . selectedItems . map ( ( item ) => {
257
259
let rendered = item . props ?. children ;
@@ -312,7 +314,8 @@ export const SelectValue = /*#__PURE__*/ (forwardRef as forwardRefType)(function
312
314
selectedItem : state . selectedItems [ 0 ] ?. value as T ?? null ,
313
315
selectedItems : useMemo ( ( ) => state . selectedItems . map ( item => item . value as T ?? null ) , [ state . selectedItems ] ) ,
314
316
selectedText,
315
- isPlaceholder : state . selectedItems . length === 0
317
+ isPlaceholder : state . selectedItems . length === 0 ,
318
+ state
316
319
}
317
320
} ) ;
318
321
0 commit comments