@@ -46,6 +46,8 @@ import { HTMLProps } from '../../utils/types';
4646import { useValueChanged } from '../../utils/useValueChanged' ;
4747import { NOOP } from '../../utils/noop' ;
4848import {
49+ hasEmptySelectionValue ,
50+ hasPrimitiveSelectionValue ,
4951 inferItemValue ,
5052 hasValueAndLabelItemsInput ,
5153 mapItemValues ,
@@ -64,24 +66,6 @@ import {
6466} from '../../utils/itemEquality' ;
6567import { INITIAL_LAST_HIGHLIGHT , NO_ACTIVE_VALUE } from './utils/constants' ;
6668
67- function hasPrimitiveSelectionValue ( value : any , multiple : boolean ) : boolean {
68- if ( multiple ) {
69- return (
70- Array . isArray ( value ) && value . length > 0 && value . every ( ( item ) => typeof item !== 'object' )
71- ) ;
72- }
73-
74- return value != null && typeof value !== 'object' ;
75- }
76-
77- function hasEmptySelectionValue ( value : any , multiple : boolean ) : boolean {
78- if ( multiple ) {
79- return Array . isArray ( value ) && value . length === 0 ;
80- }
81-
82- return value == null ;
83- }
84-
8569/**
8670 * @internal
8771 */
@@ -205,19 +189,20 @@ export function AriaCombobox<Value = any, Mode extends SelectionMode = 'none'>(
205189 name : 'Combobox' ,
206190 state : 'selectedValue' ,
207191 } ) ;
192+
208193 const hasPrimitiveSelectableItems =
209194 hasItems && selectionMode !== 'none' && hasValueAndLabelItemsInput ( items ) ;
210195 const hasEmptySelection = hasEmptySelectionValue ( selectedValue , multiple ) ;
211- const shouldUsePrimitiveValuesForItems =
196+ const usePrimitiveValuesForItems =
212197 hasPrimitiveSelectableItems && hasPrimitiveSelectionValue ( selectedValue , multiple ) ;
213- const shouldBypassItemToStringLabelForItems =
214- hasPrimitiveSelectableItems && ( shouldUsePrimitiveValuesForItems || hasEmptySelection ) ;
215- const shouldSkipPreMountItemRegistry =
216- hasPrimitiveSelectableItems && ! shouldUsePrimitiveValuesForItems && hasEmptySelection ;
217- const itemToStringLabelForItems = shouldBypassItemToStringLabelForItems
198+ const disableItemToStringLabelForItems =
199+ hasPrimitiveSelectableItems && ( usePrimitiveValuesForItems || hasEmptySelection ) ;
200+ const skipPreMountItemRegistry =
201+ hasPrimitiveSelectableItems && ! usePrimitiveValuesForItems && hasEmptySelection ;
202+ const itemToStringLabelForItems = disableItemToStringLabelForItems
218203 ? undefined
219204 : itemToStringLabel ;
220- const getVisibleItemValue = shouldUsePrimitiveValuesForItems ? inferItemValue : undefined ;
205+ const getVisibleItemValue = usePrimitiveValuesForItems ? inferItemValue : undefined ;
221206
222207 const filter = React . useMemo ( ( ) => {
223208 if ( filterProp === null ) {
@@ -500,7 +485,7 @@ export function AriaCombobox<Value = any, Mode extends SelectionMode = 'none'>(
500485
501486 const forceMount = useStableCallback ( ( ) => {
502487 if ( items ) {
503- if ( shouldSkipPreMountItemRegistry ) {
488+ if ( skipPreMountItemRegistry ) {
504489 labelsRef . current = [ ] ;
505490 valuesRef . current = [ ] ;
506491 return ;
@@ -868,22 +853,15 @@ export function AriaCombobox<Value = any, Mode extends SelectionMode = 'none'>(
868853 useIsoLayoutEffect ( ( ) => {
869854 if ( items ) {
870855 if ( ! open && ! inlineProp ) {
871- if ( shouldSkipPreMountItemRegistry ) {
856+ if ( skipPreMountItemRegistry ) {
872857 valuesRef . current = [ ] ;
873858 } else {
874859 valuesRef . current = mapItemValues ( flatFilteredItems , getVisibleItemValue ) ;
875860 }
876861 }
877862 listRef . current . length = flatFilteredItems . length ;
878863 }
879- } , [
880- items ,
881- flatFilteredItems ,
882- inlineProp ,
883- open ,
884- getVisibleItemValue ,
885- shouldSkipPreMountItemRegistry ,
886- ] ) ;
864+ } , [ items , flatFilteredItems , inlineProp , open , getVisibleItemValue , skipPreMountItemRegistry ] ) ;
887865
888866 useIsoLayoutEffect ( ( ) => {
889867 const pendingHighlight = pendingQueryHighlightRef . current ;
0 commit comments