@@ -19,28 +19,50 @@ export default function SortableElement (WrappedComponent, config = {withRef: fa
19
19
collection : 0
20
20
} ;
21
21
componentDidMount ( ) {
22
+
22
23
let { collection, disabled, index} = this . props ;
23
24
24
25
if ( ! disabled ) {
25
- let node = this . node = findDOMNode ( this ) ;
26
-
27
- node . sortableInfo = { index, collection} ;
28
-
29
- this . ref = { node} ;
30
- this . context . manager . add ( collection , this . ref ) ;
26
+ this . setDraggable ( collection , index ) ;
31
27
}
32
28
}
33
29
componentWillReceiveProps ( nextProps ) {
34
30
const { index} = this . props ;
35
31
if ( index !== nextProps . index && this . node ) {
36
32
this . node . sortableInfo . index = nextProps . index ;
37
33
}
34
+ if ( this . props . disabled !== nextProps . disabled )
35
+ {
36
+ let { collection, disabled, index} = nextProps ;
37
+ if ( disabled ) {
38
+ this . removeDraggable ( collection ) ;
39
+ }
40
+ else {
41
+ this . setDraggable ( collection , index ) ;
42
+ }
43
+ }
38
44
}
45
+
39
46
componentWillUnmount ( ) {
40
47
let { collection, disabled} = this . props ;
41
48
42
- if ( ! disabled ) this . context . manager . remove ( collection , this . ref ) ;
49
+ if ( ! disabled ) this . removeDraggable ( collection ) ;
50
+ }
51
+
52
+
53
+ setDraggable ( collection , index ) {
54
+ let node = this . node = findDOMNode ( this ) ;
55
+
56
+ node . sortableInfo = { index, collection} ;
57
+
58
+ this . ref = { node} ;
59
+ this . context . manager . add ( collection , this . ref ) ;
43
60
}
61
+
62
+ removeDraggable ( collection ) {
63
+ this . context . manager . remove ( collection , this . ref ) ;
64
+ }
65
+
44
66
getWrappedInstance ( ) {
45
67
invariant ( config . withRef , 'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableElement() call' ) ;
46
68
return this . refs . wrappedInstance ;
0 commit comments