@@ -162,6 +162,9 @@ export default function generate(config: {
162
162
163
163
RefSelect . displayName = 'Select' ;
164
164
165
+ // =================================================================================
166
+ // = Tree =
167
+ // =================================================================================
165
168
const RefTreeSelect = React . forwardRef < RefSelectProps , TreeSelectProps > ( ( props , ref ) => {
166
169
const {
167
170
multiple,
@@ -198,15 +201,6 @@ export default function generate(config: {
198
201
const treeConduction = treeCheckable && ! treeCheckStrictly ;
199
202
const mergedLabelInValue = treeCheckStrictly || labelInValue ;
200
203
201
- // ========================== Ref ==========================
202
- const selectRef = React . useRef < RefSelectProps > ( null ) ;
203
-
204
- React . useImperativeHandle ( ref , ( ) => ( {
205
- scrollTo : selectRef . current . scrollTo ,
206
- focus : selectRef . current . focus ,
207
- blur : selectRef . current . blur ,
208
- } ) ) ;
209
-
210
204
// ======================= Tree Data =======================
211
205
// Legacy both support `label` or `title` if not set.
212
206
// We have to fallback to function to handle this
@@ -242,6 +236,18 @@ export default function generate(config: {
242
236
return { keyEntities : null } ;
243
237
} , [ mergedTreeData , treeCheckable , treeCheckStrictly ] ) ;
244
238
239
+ // ========================== Ref ==========================
240
+ const selectRef = React . useRef < RefSelectProps > ( null ) ;
241
+
242
+ React . useImperativeHandle ( ref , ( ) => ( {
243
+ scrollTo : selectRef . current . scrollTo ,
244
+ focus : selectRef . current . focus ,
245
+ blur : selectRef . current . blur ,
246
+
247
+ /** @private Internal usage. It's save to remove if `rc-cascader` not use it any longer */
248
+ getEntityByValue,
249
+ } ) ) ;
250
+
245
251
// ========================= Value =========================
246
252
const [ value , setValue ] = useMergedState < DefaultValueType > ( props . defaultValue , {
247
253
value : props . value ,
@@ -569,32 +575,24 @@ export default function generate(config: {
569
575
) ;
570
576
} ) ;
571
577
572
- // Use class component since typescript not support generic
573
- // by `forwardRef` with function component yet.
574
- return class TreeSelect < ValueType = DefaultValueType > extends React . Component <
575
- TreeSelectProps < ValueType > ,
576
- { }
577
- > {
578
- static TreeNode = TreeNode ;
579
-
580
- static SHOW_ALL : typeof SHOW_ALL = SHOW_ALL ;
581
-
582
- static SHOW_PARENT : typeof SHOW_PARENT = SHOW_PARENT ;
583
-
584
- static SHOW_CHILD : typeof SHOW_CHILD = SHOW_CHILD ;
585
-
586
- selectRef = React . createRef < RefSelectProps > ( ) ;
587
-
588
- focus = ( ) => {
589
- this . selectRef . current . focus ( ) ;
590
- } ;
578
+ // =================================================================================
579
+ // = Generic =
580
+ // =================================================================================
581
+ const TreeSelect = RefTreeSelect as any as ( < ValueType = DefaultValueType > (
582
+ props : React . PropsWithChildren < TreeSelectProps < ValueType > > & {
583
+ ref ?: React . Ref < RefSelectProps > ;
584
+ } ,
585
+ ) => React . ReactElement ) & {
586
+ TreeNode : typeof TreeNode ;
587
+ SHOW_ALL : typeof SHOW_ALL ;
588
+ SHOW_PARENT : typeof SHOW_PARENT ;
589
+ SHOW_CHILD : typeof SHOW_CHILD ;
590
+ } ;
591
591
592
- blur = ( ) => {
593
- this . selectRef . current . blur ( ) ;
594
- } ;
592
+ TreeSelect . TreeNode = TreeNode ;
593
+ TreeSelect . SHOW_ALL = SHOW_ALL ;
594
+ TreeSelect . SHOW_PARENT = SHOW_PARENT ;
595
+ TreeSelect . SHOW_CHILD = SHOW_CHILD ;
595
596
596
- render ( ) {
597
- return < RefTreeSelect ref = { this . selectRef } { ...this . props } /> ;
598
- }
599
- } ;
597
+ return TreeSelect ;
600
598
}
0 commit comments