From 2d8c96c53fff10d363834aa2f48b03e437a587b9 Mon Sep 17 00:00:00 2001 From: Bram Meerten Date: Wed, 26 Jun 2024 14:58:18 +0200 Subject: [PATCH] Add support for margin and padding #154 --- lib/CSSStyleDeclaration.test.js | 8 ++++++-- lib/properties/margin.js | 1 + lib/properties/padding.js | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/CSSStyleDeclaration.test.js b/lib/CSSStyleDeclaration.test.js index 6828fa4..5509307 100644 --- a/lib/CSSStyleDeclaration.test.js +++ b/lib/CSSStyleDeclaration.test.js @@ -731,7 +731,11 @@ describe('CSSStyleDeclaration', () => { test('supports calc', () => { const style = new CSSStyleDeclaration(); - style.setProperty('width', 'calc(100% - 100px)'); - expect(style.getPropertyValue('width')).toEqual('calc(100% - 100px)'); + ['width', 'height', 'margin', 'margin-top', 'bottom', 'right', 'padding'].forEach( + (property) => { + style.setProperty(property, 'calc(100% - 100px)'); + expect(style.getPropertyValue(property)).toEqual('calc(100% - 100px)'); + } + ); }); }); diff --git a/lib/properties/margin.js b/lib/properties/margin.js index 3a42cd7..fc6f031 100644 --- a/lib/properties/margin.js +++ b/lib/properties/margin.js @@ -12,6 +12,7 @@ var isValid = function (v) { type === TYPES.NULL_OR_EMPTY_STR || type === TYPES.LENGTH || type === TYPES.PERCENT || + type === TYPES.CALC || (type === TYPES.INTEGER && (v === '0' || v === 0)) ); }; diff --git a/lib/properties/padding.js b/lib/properties/padding.js index 3848913..a82900b 100644 --- a/lib/properties/padding.js +++ b/lib/properties/padding.js @@ -9,6 +9,7 @@ var isValid = function (v) { type === TYPES.NULL_OR_EMPTY_STR || type === TYPES.LENGTH || type === TYPES.PERCENT || + type === TYPES.CALC || (type === TYPES.INTEGER && (v === '0' || v === 0)) ); };