Skip to content

Commit 6df5c1a

Browse files
Christian Klammermikesherov
authored andcommitted
Resizable: Fixed sign error on offset calculation. Fixes #9307 - Resizable: Erratic behavior of contained elements within scrollable grandparents
1 parent 9e00e00 commit 6df5c1a

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

tests/unit/resizable/resizable_events.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,51 @@ test("stop", function() {
170170

171171
});
172172

173+
test( "resize (containment) works with parent with negative offset", function() {
174+
175+
expect( 1 );
176+
177+
var widthBefore, widthAfter,
178+
handle = ".ui-resizable-e",
179+
target = $( "#resizable1" ),
180+
absoluteContainer = target.wrap( "<div />" ).parent(),
181+
fixedContainer = absoluteContainer.wrap( "<div />" ).parent(),
182+
increaseWidthBy = 50;
183+
184+
// position fixed container in window top left
185+
fixedContainer.css({
186+
width: 400,
187+
height: 100,
188+
position: "fixed",
189+
top: 0,
190+
left: 0
191+
});
192+
193+
// position absolute container within fixed on slightly outside window
194+
absoluteContainer.css({
195+
width: 400,
196+
height: 100,
197+
position: "absolute",
198+
top: 0,
199+
left: -50
200+
});
201+
202+
// set up resizable to be contained within absolute container
203+
target.resizable({
204+
handles: "all",
205+
containment: "parent"
206+
}).css({
207+
width: 300
208+
});
209+
210+
widthBefore = target.width();
211+
212+
TestHelpers.resizable.drag( handle, increaseWidthBy, 0 );
213+
214+
widthAfter = target.width();
215+
216+
equal( widthAfter, ( widthBefore + increaseWidthBy ), "resizable width should be increased by the value dragged" );
217+
218+
});
219+
173220
})(jQuery);

ui/jquery.ui.resizable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ $.ui.plugin.add("resizable", "containment", {
797797
isParent = that.containerElement.get(0) === that.element.parent().get(0);
798798
isOffsetRelative = /relative|absolute/.test(that.containerElement.css("position"));
799799

800-
if(isParent && isOffsetRelative) {
801-
woset -= that.parentData.left;
800+
if ( isParent && isOffsetRelative ) {
801+
woset -= Math.abs( that.parentData.left );
802802
}
803803

804804
if (woset + that.size.width >= that.parentData.width) {

0 commit comments

Comments
 (0)