@@ -11,24 +11,23 @@ import {
1111// divider handle is positioned at 50% width from the left-hand side
1212const DEFAULT_DIVIDER_POSITION = 0.5 ;
1313
14- const selectDividerLines = ( transform : ( dividerDOM : HTMLDivElement ) => void ) : void => {
15- document
16- . querySelectorAll < HTMLDivElement > ( "[data-test-id='divider-line']" )
17- . forEach ( transform ) ;
18- } ;
19-
20- const selectGhostDividerLines = (
14+ const selectRefs = (
15+ refs : Array < React . RefObject < HTMLDivElement > > ,
2116 transform : ( dividerDOM : HTMLDivElement ) => void
22- ) : void => {
23- document
24- . querySelectorAll < HTMLDivElement > ( "[data-test-id='divider-line-ghost']" )
25- . forEach ( transform ) ;
17+ ) => {
18+ refs . forEach ( ref => {
19+ if ( ref . current ) {
20+ transform ( ref . current ) ;
21+ }
22+ } ) ;
2623} ;
2724
2825export type DividerHandlerManagerChildrenProps = {
2926 dividerPosition : number ;
3027 setHover : ( nextHover : boolean ) => void ;
3128 onDragStart : ( event : React . MouseEvent < HTMLDivElement , MouseEvent > ) => void ;
29+ addDividerLineRef : ( ) => React . RefObject < HTMLDivElement > ;
30+ addGhostDividerLineRef : ( ) => React . RefObject < HTMLDivElement > ;
3231} ;
3332
3433type StateType = {
@@ -39,6 +38,12 @@ const DividerManagerContext = React.createContext<DividerHandlerManagerChildrenP
3938 dividerPosition : DEFAULT_DIVIDER_POSITION ,
4039 onDragStart : ( ) => { } ,
4140 setHover : ( ) => { } ,
41+ addDividerLineRef : ( ) => {
42+ return React . createRef < HTMLDivElement > ( ) ;
43+ } ,
44+ addGhostDividerLineRef : ( ) => {
45+ return React . createRef < HTMLDivElement > ( ) ;
46+ } ,
4247} ) ;
4348
4449type PropType = {
@@ -54,17 +59,31 @@ export class Provider extends React.Component<PropType, StateType> {
5459 previousUserSelect : UserSelectValues | null = null ;
5560 dividerHandlePosition : number = DEFAULT_DIVIDER_POSITION ;
5661 isDragging : boolean = false ;
62+ dividerLineRefs : Array < React . RefObject < HTMLDivElement > > = [ ] ;
63+ ghostDividerLineRefs : Array < React . RefObject < HTMLDivElement > > = [ ] ;
5764
5865 hasInteractiveLayer = ( ) : boolean => {
5966 return ! ! this . props . interactiveLayerRef . current ;
6067 } ;
6168
69+ addDividerLineRef = ( ) => {
70+ const ref = React . createRef < HTMLDivElement > ( ) ;
71+ this . dividerLineRefs . push ( ref ) ;
72+ return ref ;
73+ } ;
74+
75+ addGhostDividerLineRef = ( ) => {
76+ const ref = React . createRef < HTMLDivElement > ( ) ;
77+ this . ghostDividerLineRefs . push ( ref ) ;
78+ return ref ;
79+ } ;
80+
6281 setHover = ( nextHover : boolean ) => {
6382 if ( this . isDragging ) {
6483 return ;
6584 }
6685
67- selectDividerLines ( dividerDOM => {
86+ selectRefs ( this . dividerLineRefs , dividerDOM => {
6887 if ( nextHover ) {
6988 dividerDOM . classList . add ( 'hovering' ) ;
7089 return ;
@@ -98,11 +117,11 @@ export class Provider extends React.Component<PropType, StateType> {
98117
99118 this . isDragging = true ;
100119
101- selectDividerLines ( ( dividerDOM : HTMLDivElement ) => {
120+ selectRefs ( this . dividerLineRefs , ( dividerDOM : HTMLDivElement ) => {
102121 dividerDOM . style . backgroundColor = 'rgba(73,80,87,0.75)' ;
103122 } ) ;
104123
105- selectGhostDividerLines ( ( dividerDOM : HTMLDivElement ) => {
124+ selectRefs ( this . ghostDividerLineRefs , ( dividerDOM : HTMLDivElement ) => {
106125 dividerDOM . style . display = 'block' ;
107126 } ) ;
108127 } ;
@@ -125,7 +144,7 @@ export class Provider extends React.Component<PropType, StateType> {
125144
126145 const dividerHandlePositionString = toPercent ( this . dividerHandlePosition ) ;
127146
128- selectDividerLines ( ( dividerDOM : HTMLDivElement ) => {
147+ selectRefs ( this . dividerLineRefs , ( dividerDOM : HTMLDivElement ) => {
129148 dividerDOM . style . left = dividerHandlePositionString ;
130149 } ) ;
131150 } ;
@@ -150,11 +169,11 @@ export class Provider extends React.Component<PropType, StateType> {
150169
151170 this . isDragging = false ;
152171
153- selectDividerLines ( ( dividerDOM : HTMLDivElement ) => {
172+ selectRefs ( this . dividerLineRefs , ( dividerDOM : HTMLDivElement ) => {
154173 dividerDOM . style . backgroundColor = null ;
155174 } ) ;
156175
157- selectGhostDividerLines ( ( dividerDOM : HTMLDivElement ) => {
176+ selectRefs ( this . ghostDividerLineRefs , ( dividerDOM : HTMLDivElement ) => {
158177 dividerDOM . style . display = 'none' ;
159178 } ) ;
160179
@@ -177,6 +196,8 @@ export class Provider extends React.Component<PropType, StateType> {
177196 dividerPosition : this . state . dividerPosition ,
178197 setHover : this . setHover ,
179198 onDragStart : this . onDragStart ,
199+ addDividerLineRef : this . addDividerLineRef ,
200+ addGhostDividerLineRef : this . addGhostDividerLineRef ,
180201 } ;
181202
182203 // NOTE: <DividerManagerContext.Provider /> will not re-render its children
0 commit comments