@@ -8,19 +8,25 @@ export function getBoundPosition(draggable, clientX, clientY) {
88
99 let bounds = JSON . parse ( JSON . stringify ( draggable . props . bounds ) ) ;
1010 let node = ReactDOM . findDOMNode ( draggable ) ;
11- let parent = node . parentNode ;
1211
13- if ( bounds === 'parent' ) {
12+ if ( typeof bounds === 'string' ) {
13+ let boundNode ;
14+ if ( bounds === 'parent' ) {
15+ boundNode = node . parentNode ;
16+ } else {
17+ boundNode = document . querySelector ( bounds ) ;
18+ if ( ! boundNode ) throw new Error ( 'Bounds selector "' + bounds + '" could not find an element.' ) ;
19+ }
1420 let nodeStyle = window . getComputedStyle ( node ) ;
15- let parentStyle = window . getComputedStyle ( parent ) ;
21+ let boundNodeStyle = window . getComputedStyle ( boundNode ) ;
1622 // Compute bounds. This is a pain with padding and offsets but this gets it exactly right.
1723 bounds = {
18- left : - node . offsetLeft + int ( parentStyle . paddingLeft ) +
24+ left : - node . offsetLeft + int ( boundNodeStyle . paddingLeft ) +
1925 int ( nodeStyle . borderLeftWidth ) + int ( nodeStyle . marginLeft ) ,
20- top : - node . offsetTop + int ( parentStyle . paddingTop ) +
26+ top : - node . offsetTop + int ( boundNodeStyle . paddingTop ) +
2127 int ( nodeStyle . borderTopWidth ) + int ( nodeStyle . marginTop ) ,
22- right : innerWidth ( parent ) - outerWidth ( node ) - node . offsetLeft ,
23- bottom : innerHeight ( parent ) - outerHeight ( node ) - node . offsetTop
28+ right : innerWidth ( boundNode ) - outerWidth ( node ) - node . offsetLeft ,
29+ bottom : innerHeight ( boundNode ) - outerHeight ( node ) - node . offsetTop
2430 } ;
2531 }
2632
0 commit comments