@@ -128,6 +128,9 @@ export default class Draggable extends DraggableCore {
128128 // Current transform x and y.
129129 clientX : this . props . start . x , clientY : this . props . start . y ,
130130
131+ // Used for compensating for out-of-bounds drags
132+ slackX : 0 , slackY : 0 ,
133+
131134 // Can only determine if SVG after mounting
132135 isElementSVG : false
133136 } ;
@@ -171,7 +174,21 @@ export default class Draggable extends DraggableCore {
171174
172175 // Keep within bounds.
173176 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.
174187 [ 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 ) ;
175192 }
176193
177194 this . setState ( newState ) ;
@@ -187,7 +204,9 @@ export default class Draggable extends DraggableCore {
187204 log ( 'Draggable: onDragStop: %j' , coreEvent . position ) ;
188205
189206 this . setState ( {
190- dragging : false
207+ dragging : false ,
208+ slackX : 0 ,
209+ slackY : 0
191210 } ) ;
192211 } ;
193212
0 commit comments