@@ -12,7 +12,6 @@ import ScrollSyncContext from './support/ScrollSyncContext'
12
12
* @example ./example.md
13
13
*/
14
14
15
-
16
15
export default class ScrollSyncPane extends Component {
17
16
static contextType = ScrollSyncContext ;
18
17
@@ -22,18 +21,26 @@ export default class ScrollSyncPane extends Component {
22
21
PropTypes . func ,
23
22
PropTypes . shape ( { current : PropTypes . any } )
24
23
] ) ,
25
- group : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . arrayOf ( PropTypes . string ) ] ) ,
26
- enabled : PropTypes . bool
27
- }
24
+ group : PropTypes . oneOfType ( [
25
+ PropTypes . string ,
26
+ PropTypes . arrayOf ( PropTypes . string )
27
+ ] ) ,
28
+ enabled : PropTypes . bool ,
29
+ innerRef : PropTypes . oneOfType ( [ // Either a function
30
+ PropTypes . func ,
31
+ // Or the instance of a DOM native element (see the note about SSR)
32
+ PropTypes . shape ( { current : PropTypes . instanceOf ( Element ) } ) ] )
33
+ } ;
28
34
29
35
static defaultProps = {
30
36
group : 'default' ,
31
37
enabled : true
32
- }
38
+ } ;
33
39
34
40
constructor ( props ) {
35
41
super ( props )
36
- this . childRef = createRef ( )
42
+
43
+ this . childRef = props . innerRef ? props . innerRef : createRef ( )
37
44
}
38
45
39
46
componentDidMount ( ) {
@@ -62,7 +69,11 @@ export default class ScrollSyncPane extends Component {
62
69
this . context . unregisterPane ( this . node , this . toArray ( prevProps . group ) )
63
70
}
64
71
}
65
- if ( this . node && this . props . enabled && this . props . group !== prevProps . group ) {
72
+ if (
73
+ this . node &&
74
+ this . props . enabled &&
75
+ this . props . group !== prevProps . group
76
+ ) {
66
77
this . context . unregisterPane ( this . node , this . toArray ( prevProps . group ) )
67
78
this . context . registerPane ( this . node , this . toArray ( this . props . group ) )
68
79
}
@@ -74,20 +85,22 @@ export default class ScrollSyncPane extends Component {
74
85
}
75
86
}
76
87
77
- toArray = groups => [ ] . concat ( groups )
88
+ toArray = groups => [ ] . concat ( groups ) ;
78
89
79
90
updateNode = ( ) => {
80
91
if ( this . props . attachTo ) {
81
92
this . node = this . props . attachTo . current
82
93
} else {
83
94
this . node = this . childRef . current
84
95
}
85
- }
96
+ } ;
86
97
87
98
render ( ) {
88
99
if ( this . props . attachTo ) {
89
100
return this . props . children
90
101
}
91
- return cloneElement ( Children . only ( this . props . children ) , { ref : this . childRef } )
102
+ return cloneElement ( Children . only ( this . props . children ) , {
103
+ ref : this . childRef
104
+ } )
92
105
}
93
106
}
0 commit comments