@@ -8,19 +8,25 @@ export function getBoundPosition(draggable, clientX, clientY) {
8
8
9
9
let bounds = JSON . parse ( JSON . stringify ( draggable . props . bounds ) ) ;
10
10
let node = ReactDOM . findDOMNode ( draggable ) ;
11
- let parent = node . parentNode ;
12
11
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
+ }
14
20
let nodeStyle = window . getComputedStyle ( node ) ;
15
- let parentStyle = window . getComputedStyle ( parent ) ;
21
+ let boundNodeStyle = window . getComputedStyle ( boundNode ) ;
16
22
// Compute bounds. This is a pain with padding and offsets but this gets it exactly right.
17
23
bounds = {
18
- left : - node . offsetLeft + int ( parentStyle . paddingLeft ) +
24
+ left : - node . offsetLeft + int ( boundNodeStyle . paddingLeft ) +
19
25
int ( nodeStyle . borderLeftWidth ) + int ( nodeStyle . marginLeft ) ,
20
- top : - node . offsetTop + int ( parentStyle . paddingTop ) +
26
+ top : - node . offsetTop + int ( boundNodeStyle . paddingTop ) +
21
27
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
24
30
} ;
25
31
}
26
32
0 commit comments