@@ -11,7 +11,7 @@ import {
11
11
UNSELECTABLE_ATTRIBUTE , UNSELECTABLE_STYLE ,
12
12
preventDefaultEvent , findFirstMenuItem ,
13
13
includesSeparators , splitBySeparators ,
14
- findIndexInValueByLabel , defaultFilterFn ,
14
+ findIndexInValueByLabel , defaultFilterFn , saveRef ,
15
15
} from './util' ;
16
16
import SelectTrigger from './SelectTrigger' ;
17
17
import { SelectPropTypes } from './PropTypes' ;
@@ -21,10 +21,6 @@ import warning from 'warning';
21
21
function noop ( ) {
22
22
}
23
23
24
- function saveRef ( name , component ) {
25
- this [ name ] = component ;
26
- }
27
-
28
24
function chaining ( ...fns ) {
29
25
return function ( ...args ) { // eslint-disable-line
30
26
for ( let i = 0 ; i < fns . length ; i ++ ) {
@@ -78,6 +74,9 @@ constructor(props) {
78
74
}
79
75
this . saveInputRef = saveRef . bind ( this , 'inputInstance' ) ;
80
76
this . saveInputMirrorRef = saveRef . bind ( this , 'inputMirrorInstance' ) ;
77
+ this . saveRootRef = saveRef . bind ( this , 'rootInstance' ) ;
78
+ this . saveSelectionRef = saveRef . bind ( this , 'selectionInstance' ) ;
79
+ this . saveTriggerRef = saveRef . bind ( this , 'triggerInstance' ) ;
81
80
let open = props . open ;
82
81
if ( open === undefined ) {
83
82
open = props . defaultOpen ;
@@ -216,7 +215,7 @@ constructor(props) {
216
215
}
217
216
218
217
if ( state . open ) {
219
- const menu = this . refs . trigger . getInnerMenu ( ) ;
218
+ const menu = this . triggerInstance . getInnerMenu ( ) ;
220
219
if ( menu && menu . onKeyDown ( event ) ) {
221
220
event . preventDefault ( ) ;
222
221
event . stopPropagation ( ) ;
@@ -362,7 +361,7 @@ constructor(props) {
362
361
}
363
362
364
363
onChoiceAnimationLeave = ( ) => {
365
- this . refs . trigger . refs . trigger . forcePopupAlign ( ) ;
364
+ this . triggerInstance . triggerInstance . forcePopupAlign ( ) ;
366
365
}
367
366
368
367
getLabelBySingleValue = ( children , value ) => {
@@ -505,11 +504,11 @@ constructor(props) {
505
504
}
506
505
507
506
getPopupDOMNode = ( ) => {
508
- return this . refs . trigger . getPopupDOMNode ( ) ;
507
+ return this . triggerInstance . getPopupDOMNode ( ) ;
509
508
}
510
509
511
510
getPopupMenuComponent = ( ) => {
512
- return this . refs . trigger . getInnerMenu ( ) ;
511
+ return this . triggerInstance . getInnerMenu ( ) ;
513
512
}
514
513
515
514
setOpenState = ( open , needFocus ) => {
@@ -600,12 +599,12 @@ constructor(props) {
600
599
}
601
600
602
601
updateFocusClassName = ( ) => {
603
- const { refs , props } = this ;
602
+ const { rootInstance , props } = this ;
604
603
// avoid setState and its side effect
605
604
if ( this . _focused ) {
606
- classes ( refs . root ) . add ( `${ props . prefixCls } -focused` ) ;
605
+ classes ( rootInstance ) . add ( `${ props . prefixCls } -focused` ) ;
607
606
} else {
608
- classes ( refs . root ) . remove ( `${ props . prefixCls } -focused` ) ;
607
+ classes ( rootInstance ) . remove ( `${ props . prefixCls } -focused` ) ;
609
608
}
610
609
}
611
610
@@ -619,7 +618,7 @@ constructor(props) {
619
618
this . _focused = true ;
620
619
}
621
620
} else {
622
- const selection = this . refs . selection ;
621
+ const selection = this . selectionInstance ;
623
622
if ( activeElement !== selection ) {
624
623
selection . focus ( ) ;
625
624
this . _focused = true ;
@@ -1036,17 +1035,17 @@ constructor(props) {
1036
1035
getPopupContainer = { props . getPopupContainer }
1037
1036
onMenuSelect = { this . onMenuSelect }
1038
1037
onMenuDeselect = { this . onMenuDeselect }
1039
- ref = "trigger"
1038
+ ref = { this . saveTriggerRef }
1040
1039
>
1041
1040
< div
1042
1041
style = { props . style }
1043
- ref = "root"
1042
+ ref = { this . saveRootRef }
1044
1043
onBlur = { this . onOuterBlur }
1045
1044
onFocus = { this . onOuterFocus }
1046
1045
className = { classnames ( rootCls ) }
1047
1046
>
1048
1047
< div
1049
- ref = "selection"
1048
+ ref = { this . saveSelectionRef }
1050
1049
key = "selection"
1051
1050
className = { `${ prefixCls } -selection
1052
1051
${ prefixCls } -selection--${ multiple ? 'multiple' : 'single' } ` }
0 commit comments