From 07f267a260f28ab0f5620ab18c3f09de164532e0 Mon Sep 17 00:00:00 2001 From: chtheis Date: Sun, 18 Nov 2018 21:10:35 +0000 Subject: [PATCH 1/2] Correct calculation of padding in percent --- src/core/core.helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 4b0a18c1648..3b1eca5edb3 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -499,7 +499,7 @@ module.exports = function() { helpers._calculatePadding = function(container, padding, parentDimension) { padding = helpers.getStyle(container, padding); - return padding.indexOf('%') > -1 ? parentDimension / parseInt(padding, 10) : parseInt(padding, 10); + return padding.indexOf('%') > -1 ? parentDimension * parseInt(padding, 10) / 100 : parseInt(padding, 10); }; /** * @private From e78aa7d21d1b76c736c74776a6994a98465e857d Mon Sep 17 00:00:00 2001 From: chtheis Date: Mon, 19 Nov 2018 09:37:27 +0000 Subject: [PATCH 2/2] Testcase for padding in percent with something else than 10% --- test/specs/core.helpers.tests.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/specs/core.helpers.tests.js b/test/specs/core.helpers.tests.js index de6d0b41301..70f0981df0e 100644 --- a/test/specs/core.helpers.tests.js +++ b/test/specs/core.helpers.tests.js @@ -790,7 +790,7 @@ describe('Core helper tests', function() { div.style.height = '300px'; document.body.appendChild(div); - // Inner DIV to have 10% padding of parent + // Inner DIV to have 5% padding of parent var innerDiv = document.createElement('div'); div.appendChild(innerDiv); @@ -802,8 +802,8 @@ describe('Core helper tests', function() { expect(helpers.getMaximumWidth(canvas)).toBe(300); // test with percentage - innerDiv.style.padding = '10%'; - expect(helpers.getMaximumWidth(canvas)).toBe(240); + innerDiv.style.padding = '5%'; + expect(helpers.getMaximumWidth(canvas)).toBe(270); // test with pixels innerDiv.style.padding = '10px';