@@ -128,6 +128,9 @@ export default class Draggable extends DraggableCore {
128
128
// Current transform x and y.
129
129
clientX : this . props . start . x , clientY : this . props . start . y ,
130
130
131
+ // Used for compensating for out-of-bounds drags
132
+ slackX : 0 , slackY : 0 ,
133
+
131
134
// Can only determine if SVG after mounting
132
135
isElementSVG : false
133
136
} ;
@@ -171,7 +174,21 @@ export default class Draggable extends DraggableCore {
171
174
172
175
// Keep within bounds.
173
176
if ( this . props . bounds ) {
177
+ // Save original x and y.
178
+ let { clientX, clientY} = newState ;
179
+
180
+ // Add slack to the values used to calculate bound position. This will ensure that if
181
+ // we start removing slack, the element won't react to it right away until it's been
182
+ // completely removed.
183
+ newState . clientX += this . state . slackX ;
184
+ newState . clientY += this . state . slackY ;
185
+
186
+ // Get bound position. This will ceil/floor the x and y within the boundaries.
174
187
[ newState . clientX , newState . clientY ] = getBoundPosition ( this , newState . clientX , newState . clientY ) ;
188
+
189
+ // Recalculate slack by noting how much was shaved by the boundPosition handler.
190
+ newState . slackX = this . state . slackX + ( clientX - newState . clientX ) ;
191
+ newState . slackY = this . state . slackY + ( clientY - newState . clientY ) ;
175
192
}
176
193
177
194
this . setState ( newState ) ;
@@ -187,7 +204,9 @@ export default class Draggable extends DraggableCore {
187
204
log ( 'Draggable: onDragStop: %j' , coreEvent . position ) ;
188
205
189
206
this . setState ( {
190
- dragging : false
207
+ dragging : false ,
208
+ slackX : 0 ,
209
+ slackY : 0
191
210
} ) ;
192
211
} ;
193
212
0 commit comments