From c934995efa431efe0b15b6f9a6b614e6b8e88399 Mon Sep 17 00:00:00 2001
From: Daniel GarcĂa <93217193+Daniel-Garmig@users.noreply.github.com>
Date: Mon, 9 Sep 2024 23:51:57 +0200
Subject: Resizable: Fix content shrink on resize
Make resizable elements not shrink on resize when they have scrollbars
and "box-sizing: content-box".
Fixes: gh-2277
Closes gh-2281
---
tests/unit/resizable/core.js | 68 +++++++++++++++++++++++++++++++++++++++++
tests/unit/resizable/options.js | 62 ++++++++++++++++++++++++++++++++-----
2 files changed, 123 insertions(+), 7 deletions(-)
(limited to 'tests')
diff --git a/tests/unit/resizable/core.js b/tests/unit/resizable/core.js
index b3c61514a..b47f0b645 100644
--- a/tests/unit/resizable/core.js
+++ b/tests/unit/resizable/core.js
@@ -244,4 +244,72 @@ QUnit.test( "nested resizable", function( assert ) {
outer.remove();
} );
+QUnit.test( "Resizable with scrollbars and box-sizing: border-box", function( assert ) {
+ assert.expect( 4 );
+ testResizableWithBoxSizing( assert, {
+ isBorderBox: true,
+ applyScaleTransform: false
+ } );
+} );
+
+QUnit.test( "Resizable with scrollbars and box-sizing: content-box", function( assert ) {
+ assert.expect( 4 );
+ testResizableWithBoxSizing( assert, {
+ isBorderBox: false,
+ applyScaleTransform: false
+ } );
+} );
+
+QUnit.test( "Resizable with scrollbars, a transform and box-sizing: border-box", function( assert ) {
+ assert.expect( 4 );
+ testResizableWithBoxSizing( assert, {
+ isBorderBox: true,
+ applyScaleTransform: true
+ } );
+} );
+
+QUnit.test( "Resizable with scrollbars, a transform and box-sizing: content-box", function( assert ) {
+ assert.expect( 4 );
+ testResizableWithBoxSizing( assert, {
+ isBorderBox: false,
+ applyScaleTransform: true
+ } );
+} );
+
+function testResizableWithBoxSizing( assert, options ) {
+ var widthBefore, heightBefore,
+ cssBoxSizing = options.isBorderBox ? "border-box" : "content-box",
+ cssTransform = options.applyScaleTransform ? "scale(1.5)" : "",
+ elementContent = $( "
" )
+ .css( {
+ width: "200px",
+ height: "200px",
+ padding: "10px",
+ border: "5px",
+ borderStyle: "solid",
+ margin: "20px"
+ } )
+ .appendTo( "#resizable1" ),
+ element = $( "#resizable1" ).css( { overflow: "auto", transform: cssTransform } ).resizable(),
+ handle = ".ui-resizable-se";
+
+ $( "" ).appendTo( "#qunit-fixture" );
+
+ // In some browsers scrollbar may change element size (when "box-sizing: content-box")
+ widthBefore = element.innerWidth();
+ heightBefore = element.innerHeight();
+
+ // Both scrollbars
+ testHelper.drag( handle, 10, 10 );
+ assert.equal( parseFloat( element.innerWidth() ), widthBefore + 10, "element width (both scrollbars)" );
+ assert.equal( parseFloat( element.innerHeight() ), heightBefore + 10, "element height (both scrollbars)" );
+
+ // Single (vertical) scrollbar.
+ elementContent.css( "width", "50px" );
+
+ testHelper.drag( handle, 10, 10 );
+ assert.equal( parseFloat( element.innerWidth() ), widthBefore + 20, "element width (only vertical scrollbar)" );
+ assert.equal( parseFloat( element.innerHeight() ), heightBefore + 20, "element height (only vertical scrollbar)" );
+}
+
} );
diff --git a/tests/unit/resizable/options.js b/tests/unit/resizable/options.js
index add8d8034..b80c051d5 100644
--- a/tests/unit/resizable/options.js
+++ b/tests/unit/resizable/options.js
@@ -542,21 +542,22 @@ QUnit.test( "alsoResize + multiple selection", function( assert ) {
QUnit.test( "alsoResize with box-sizing: border-box", function( assert ) {
assert.expect( 4 );
+ $( "" ).appendTo( "#qunit-fixture" );
+
var other = $( "
" )
.css( {
- width: 50,
- height: 50,
- padding: 10,
- border: 5
+ width: "50px",
+ height: "50px",
+ padding: "10px",
+ border: "5px",
+ borderStyle: "solid"
} )
- .appendTo( "body" ),
+ .appendTo( "#qunit-fixture" ),
element = $( "#resizable1" ).resizable( {
alsoResize: other
} ),
handle = ".ui-resizable-se";
- $( "*" ).css( "box-sizing", "border-box" );
-
testHelper.drag( handle, 80, 80 );
assert.equal( element.width(), 180, "resizable width" );
@@ -565,4 +566,51 @@ QUnit.test( "alsoResize with box-sizing: border-box", function( assert ) {
assert.equal( parseFloat( other.css( "height" ) ), 130, "alsoResize height" );
} );
+QUnit.test( "alsoResize with scrollbars and box-sizing: border-box", function( assert ) {
+ assert.expect( 4 );
+ testAlsoResizeWithBoxSizing( assert, {
+ isBorderBox: true
+ } );
+} );
+
+QUnit.test( "alsoResize with scrollbars and box-sizing: content-box", function( assert ) {
+ assert.expect( 4 );
+ testAlsoResizeWithBoxSizing( assert, {
+ isBorderBox: false
+ } );
+} );
+
+function testAlsoResizeWithBoxSizing( assert, options ) {
+ var widthBefore, heightBefore,
+ cssBoxSizing = options.isBorderBox ? "border-box" : "content-box",
+ other = $( "
" )
+ .css( {
+ width: "150px",
+ height: "150px",
+ padding: "10px",
+ border: "5px",
+ borderStyle: "solid",
+ margin: "20px",
+ overflow: "scroll"
+ } )
+ .appendTo( "#qunit-fixture" ),
+ element = $( "#resizable1" ).resizable( {
+ alsoResize: other
+ } ),
+ handle = ".ui-resizable-se";
+
+ $( "" ).appendTo( "#qunit-fixture" );
+
+ // In some browsers scrollbar may change element computed size.
+ widthBefore = other.innerWidth();
+ heightBefore = other.innerHeight();
+
+ testHelper.drag( handle, 80, 80 );
+
+ assert.equal( element.width(), 180, "resizable width" );
+ assert.equal( parseFloat( other.innerWidth() ), widthBefore + 80, "alsoResize width" );
+ assert.equal( element.height(), 180, "resizable height" );
+ assert.equal( parseFloat( other.innerHeight() ), heightBefore + 80, "alsoResize height" );
+}
+
} );
--
cgit v1.2.3