1
- import * as React from 'react' ;
2
- import { BaseSelect } from 'rc-select' ;
3
- import type { IconType } from 'rc-tree/lib/interface' ;
4
- import type { ExpandAction } from 'rc-tree/lib/Tree' ;
5
1
import type {
6
- BaseSelectRef ,
7
- BaseSelectPropsWithoutPrivate ,
8
2
BaseSelectProps ,
3
+ BaseSelectPropsWithoutPrivate ,
4
+ BaseSelectRef ,
9
5
SelectProps ,
10
6
} from 'rc-select' ;
11
- import { conductCheck } from 'rc-tree/lib/utils/conductUtil ' ;
7
+ import { BaseSelect } from 'rc-select ' ;
12
8
import useId from 'rc-select/lib/hooks/useId' ;
9
+ import type { IconType } from 'rc-tree/lib/interface' ;
10
+ import type { ExpandAction } from 'rc-tree/lib/Tree' ;
11
+ import { conductCheck } from 'rc-tree/lib/utils/conductUtil' ;
13
12
import useMergedState from 'rc-util/lib/hooks/useMergedState' ;
13
+ import warning from 'rc-util/lib/warning' ;
14
+ import * as React from 'react' ;
15
+ import useCache from './hooks/useCache' ;
16
+ import useCheckedKeys from './hooks/useCheckedKeys' ;
17
+ import useDataEntities from './hooks/useDataEntities' ;
18
+ import useFilterTreeData from './hooks/useFilterTreeData' ;
19
+ import useRefFunc from './hooks/useRefFunc' ;
20
+ import useTreeData from './hooks/useTreeData' ;
21
+ import LegacyContext from './LegacyContext' ;
14
22
import OptionList from './OptionList' ;
15
23
import TreeNode from './TreeNode' ;
16
- import { formatStrategyValues , SHOW_ALL , SHOW_PARENT , SHOW_CHILD } from './utils/strategyUtil' ;
17
- import type { CheckedStrategy } from './utils/strategyUtil' ;
18
- import TreeSelectContext from './TreeSelectContext' ;
19
24
import type { TreeSelectContextProps } from './TreeSelectContext' ;
20
- import LegacyContext from './LegacyContext' ;
21
- import useTreeData from './hooks/useTreeData' ;
22
- import { toArray , fillFieldNames , isNil } from './utils/valueUtil' ;
23
- import useCache from './hooks/useCache' ;
24
- import useRefFunc from './hooks/useRefFunc' ;
25
- import useDataEntities from './hooks/useDataEntities' ;
25
+ import TreeSelectContext from './TreeSelectContext' ;
26
26
import { fillAdditionalInfo , fillLegacyProps } from './utils/legacyUtil' ;
27
- import useCheckedKeys from './hooks/useCheckedKeys' ;
28
- import useFilterTreeData from './hooks/useFilterTreeData' ;
27
+ import type { CheckedStrategy } from './utils/strategyUtil' ;
28
+ import { formatStrategyValues , SHOW_ALL , SHOW_CHILD , SHOW_PARENT } from './utils/strategyUtil' ;
29
+ import { fillFieldNames , isNil , toArray } from './utils/valueUtil' ;
29
30
import warningProps from './utils/warningPropsUtil' ;
30
- import warning from 'rc-util/lib/warning' ;
31
31
32
32
export type OnInternalSelect = ( value : RawValueType , info : { selected : boolean } ) => void ;
33
33
@@ -105,7 +105,7 @@ export interface LegacyDataNode extends DefaultOptionType {
105
105
}
106
106
export interface TreeSelectProps <
107
107
ValueType = any ,
108
- OptionType extends BaseOptionType = DefaultOptionType
108
+ OptionType extends BaseOptionType = DefaultOptionType ,
109
109
> extends Omit < BaseSelectPropsWithoutPrivate , 'mode' > {
110
110
prefixCls ?: string ;
111
111
id ?: string ;
@@ -194,7 +194,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
194
194
treeNodeFilterProp = 'value' ,
195
195
196
196
// Selector
197
- showCheckedStrategy = SHOW_CHILD ,
197
+ showCheckedStrategy,
198
198
treeNodeLabelProp,
199
199
200
200
// Mode
@@ -246,6 +246,15 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
246
246
247
247
const [ internalValue , setInternalValue ] = useMergedState ( defaultValue , { value } ) ;
248
248
249
+ // `multiple` && `!treeCheckable` should be show all
250
+ const mergedShowCheckedStrategy = React . useMemo ( ( ) => {
251
+ if ( ! treeCheckable ) {
252
+ return SHOW_ALL ;
253
+ }
254
+
255
+ return showCheckedStrategy || SHOW_CHILD ;
256
+ } , [ showCheckedStrategy , treeCheckable ] ) ;
257
+
249
258
// ========================== Warning ===========================
250
259
if ( process . env . NODE_ENV !== 'production' ) {
251
260
warningProps ( props ) ;
@@ -357,7 +366,9 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
357
366
rawDisabled = entity . node . disabled ;
358
367
} else if ( rawLabel === undefined ) {
359
368
// We try to find in current `labelInValue` value
360
- const labelInValueItem = toLabeledValues ( internalValue ) . find ( labeledItem => labeledItem . value === rawValue ) ;
369
+ const labelInValueItem = toLabeledValues ( internalValue ) . find (
370
+ labeledItem => labeledItem . value === rawValue ,
371
+ ) ;
361
372
rawLabel = labelInValueItem . label ;
362
373
}
363
374
@@ -373,10 +384,10 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
373
384
) ;
374
385
375
386
// =========================== Values ===========================
376
- const rawMixedLabeledValues = React . useMemo ( ( ) => toLabeledValues ( internalValue ) , [
377
- toLabeledValues ,
378
- internalValue ,
379
- ] ) ;
387
+ const rawMixedLabeledValues = React . useMemo (
388
+ ( ) => toLabeledValues ( internalValue ) ,
389
+ [ toLabeledValues , internalValue ] ,
390
+ ) ;
380
391
381
392
// Split value into full check and half check
382
393
const [ rawLabeledValues , rawHalfLabeledValues ] = React . useMemo ( ( ) => {
@@ -395,9 +406,10 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
395
406
} , [ rawMixedLabeledValues ] ) ;
396
407
397
408
// const [mergedValues] = useCache(rawLabeledValues);
398
- const rawValues = React . useMemo ( ( ) => rawLabeledValues . map ( item => item . value ) , [
399
- rawLabeledValues ,
400
- ] ) ;
409
+ const rawValues = React . useMemo (
410
+ ( ) => rawLabeledValues . map ( item => item . value ) ,
411
+ [ rawLabeledValues ] ,
412
+ ) ;
401
413
402
414
// Convert value to key. Will fill missed keys for conduct check.
403
415
const [ rawCheckedValues , rawHalfCheckedValues ] = useCheckedKeys (
@@ -412,7 +424,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
412
424
// Collect keys which need to show
413
425
const displayKeys = formatStrategyValues (
414
426
rawCheckedValues ,
415
- showCheckedStrategy ,
427
+ mergedShowCheckedStrategy ,
416
428
keyEntities ,
417
429
mergedFieldNames ,
418
430
) ;
@@ -447,7 +459,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
447
459
rawCheckedValues ,
448
460
rawLabeledValues ,
449
461
convert2LabelValues ,
450
- showCheckedStrategy ,
462
+ mergedShowCheckedStrategy ,
451
463
keyEntities ,
452
464
] ) ;
453
465
@@ -474,7 +486,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
474
486
if ( treeConduction ) {
475
487
const formattedKeyList = formatStrategyValues (
476
488
newRawValues ,
477
- showCheckedStrategy ,
489
+ mergedShowCheckedStrategy ,
478
490
keyEntities ,
479
491
mergedFieldNames ,
480
492
) ;
@@ -743,9 +755,9 @@ if (process.env.NODE_ENV !== 'production') {
743
755
TreeSelect . displayName = 'TreeSelect' ;
744
756
}
745
757
746
- const GenericTreeSelect = ( TreeSelect as unknown ) as ( <
758
+ const GenericTreeSelect = TreeSelect as unknown as ( <
747
759
ValueType = any ,
748
- OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType
760
+ OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType ,
749
761
> (
750
762
props : React . PropsWithChildren < TreeSelectProps < ValueType , OptionType > > & {
751
763
ref ?: React . Ref < BaseSelectRef > ;
0 commit comments