Skip to content

Commit e9efbc2

Browse files
committed
Draggable: consider offsets from overflow:hidden parents
Developers can programmatically set scrollTop/Left on draggable containers that are overflow:hidden. They must be considered for positioning. Fixes #10147
1 parent 67e4b44 commit e9efbc2

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

tests/unit/draggable/draggable_core.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -185,38 +185,44 @@ test( "#5009: scroll not working with parent's position fixed", function() {
185185
});
186186
});
187187

188-
test( "#9379: Draggable: position bug in scrollable div", function() {
189-
expect( 2 );
190-
191-
$( "#qunit-fixture" ).html( "<div id='o_9379'><div id='i_9379'></div><div id='d_9379'>a</div></div>" );
192-
$( "#i_9379" ).css({ position: "absolute", width: "500px", height: "500px" });
193-
$( "#o_9379" ).css({ position: "absolute", width: "300px", height: "300px" });
194-
$( "#d_9379" ).css({ width: "10px", height: "10px" });
195-
196-
var moves = 3,
197-
startValue = 0,
198-
dragDelta = 20,
199-
delta = 100,
188+
$( [ "hidden", "auto", "scroll" ] ).each(function() {
189+
var overflow = this;
190+
191+
// http://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div
192+
// http://bugs.jqueryui.com/ticket/10147 - Wrong position in a parent with "overflow: hidden"
193+
test( "position in scrollable parent with overflow: " + overflow, function() {
194+
expect( 2 );
195+
196+
$( "#qunit-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" );
197+
$( "#inner" ).css({ position: "absolute", width: "500px", height: "500px" });
198+
$( "#outer" ).css({ position: "absolute", width: "300px", height: "300px" });
199+
$( "#dragged" ).css({ width: "10px", height: "10px" });
200+
201+
var moves = 3,
202+
startValue = 0,
203+
dragDelta = 20,
204+
delta = 100,
205+
206+
// we scroll after each drag event, so subtract 1 from number of moves for expected
207+
expected = delta + ( ( moves - 1 ) * dragDelta ),
208+
element = $( "#dragged" ).draggable({
209+
drag: function() {
210+
startValue += dragDelta;
211+
$( "#outer" ).scrollTop( startValue ).scrollLeft( startValue );
212+
},
213+
stop: function( event, ui ) {
214+
equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" );
215+
equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
216+
}
217+
});
218+
219+
$( "#outer" ).css( "overflow", overflow );
200220

201-
// we scroll after each drag event, so subtract 1 from number of moves for expected
202-
expected = delta + ( ( moves - 1 ) * dragDelta ),
203-
element = $( "#d_9379" ).draggable({
204-
drag: function() {
205-
startValue += dragDelta;
206-
$( "#o_9379" ).scrollTop( startValue ).scrollLeft( startValue );
207-
},
208-
stop: function( event, ui ) {
209-
equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" );
210-
equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
211-
}
221+
element.simulate( "drag", {
222+
dy: delta,
223+
dx: delta,
224+
moves: moves
212225
});
213-
214-
$( "#o_9379" ).css( "overflow", "auto" );
215-
216-
element.simulate( "drag", {
217-
dy: delta,
218-
dx: delta,
219-
moves: moves
220226
});
221227
});
222228

tests/unit/draggable/draggable_options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ test( "containment, account for border", function() {
361361
el.css({
362362
height: "5px",
363363
width: "5px"
364-
}).draggable({ containment: "parent" });
364+
}).draggable({ containment: "parent", scroll: false });
365365

366366
el.simulate( "drag", {
367367
dx: 100,

ui/draggable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ $.widget("ui.draggable", $.ui.mouse, {
161161

162162
//Store the helper's css position
163163
this.cssPosition = this.helper.css( "position" );
164-
this.scrollParent = this.helper.scrollParent();
164+
this.scrollParent = this.helper.scrollParent( true );
165165
this.offsetParent = this.helper.offsetParent();
166166
this.offsetParentCssPosition = this.offsetParent.css( "position" );
167167

0 commit comments

Comments
 (0)