@@ -40,6 +40,7 @@ import useLayoutEffect from './hooks/useLayoutEffect';
40
40
import { getSeparatedContent } from './utils/valueUtil' ;
41
41
import useSelectTriggerControl from './hooks/useSelectTriggerControl' ;
42
42
import useCacheDisplayValue from './hooks/useCacheDisplayValue' ;
43
+ import useCacheOptions from './hooks/useCacheOptions' ;
43
44
44
45
const DEFAULT_OMIT_PROPS = [
45
46
'removeIcon' ,
@@ -419,6 +420,8 @@ export default function generateSelector<
419
420
[ mergedOptions ] ,
420
421
) ;
421
422
423
+ const getValueOption = useCacheOptions ( mergedRawValue , mergedFlattenOptions ) ;
424
+
422
425
// Display options for OptionList
423
426
const displayOptions = React . useMemo < OptionsType > ( ( ) => {
424
427
if ( ! mergedSearchValue || ! mergedShowSearch ) {
@@ -454,16 +457,17 @@ export default function generateSelector<
454
457
let displayValues = React . useMemo < DisplayLabelValueType [ ] > (
455
458
( ) =>
456
459
mergedRawValue . map ( ( val : RawValueType ) => {
460
+ const valueOptions = getValueOption ( [ val ] ) ;
457
461
const displayValue = getLabeledValue ( val , {
458
- options : mergedFlattenOptions ,
462
+ options : valueOptions ,
459
463
prevValue : baseValue ,
460
464
labelInValue : mergedLabelInValue ,
461
465
optionLabelProp : mergedOptionLabelProp ,
462
466
} ) ;
463
467
464
468
return {
465
469
...displayValue ,
466
- disabled : isValueDisabled ( val , mergedFlattenOptions ) ,
470
+ disabled : isValueDisabled ( val , valueOptions ) ,
467
471
} ;
468
472
} ) ,
469
473
[ baseValue , mergedOptions ] ,
@@ -473,13 +477,14 @@ export default function generateSelector<
473
477
displayValues = useCacheDisplayValue ( displayValues ) ;
474
478
475
479
const triggerSelect = ( newValue : RawValueType , isSelect : boolean , source : SelectSource ) => {
476
- const outOption = findValueOption ( [ newValue ] , mergedFlattenOptions ) [ 0 ] ;
480
+ const newValueOption = getValueOption ( [ newValue ] ) ;
481
+ const outOption = findValueOption ( [ newValue ] , newValueOption ) [ 0 ] ;
477
482
478
483
if ( ! internalProps . skipTriggerSelect ) {
479
484
// Skip trigger `onSelect` or `onDeselect` if configured
480
485
const selectValue = ( mergedLabelInValue
481
486
? getLabeledValue ( newValue , {
482
- options : mergedFlattenOptions ,
487
+ options : newValueOption ,
483
488
prevValue : baseValue ,
484
489
labelInValue : mergedLabelInValue ,
485
490
optionLabelProp : mergedOptionLabelProp ,
@@ -507,10 +512,10 @@ export default function generateSelector<
507
512
if ( useInternalProps && internalProps . skipTriggerChange ) {
508
513
return ;
509
514
}
510
-
515
+ const newRawValuesOptions = getValueOption ( newRawValues ) ;
511
516
const outValues = toOuterValues < FlattenOptionsType < OptionsType > > ( Array . from ( newRawValues ) , {
512
517
labelInValue : mergedLabelInValue ,
513
- options : mergedFlattenOptions ,
518
+ options : newRawValuesOptions ,
514
519
getLabeledValue,
515
520
prevValue : baseValue ,
516
521
optionLabelProp : mergedOptionLabelProp ,
@@ -519,7 +524,7 @@ export default function generateSelector<
519
524
const outValue : ValueType = ( isMultiple ? outValues : outValues [ 0 ] ) as ValueType ;
520
525
// Skip trigger if prev & current value is both empty
521
526
if ( onChange && ( mergedRawValue . length !== 0 || outValues . length !== 0 ) ) {
522
- const outOptions = findValueOption ( newRawValues , mergedFlattenOptions ) ;
527
+ const outOptions = findValueOption ( newRawValues , newRawValuesOptions ) ;
523
528
524
529
onChange ( outValue , isMultiple ? outOptions : outOptions [ 0 ] ) ;
525
530
}
0 commit comments