From db0708250e46074bdf9c0ad2943c36544a66c5c8 Mon Sep 17 00:00:00 2001 From: Roman Bruckner Date: Thu, 11 Jul 2024 11:40:09 +0200 Subject: [PATCH] fix(mvc.View): set style via options (#2705) --- packages/joint-core/src/mvc/ViewBase.mjs | 3 ++- packages/joint-core/test/jointjs/mvc.view.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/joint-core/src/mvc/ViewBase.mjs b/packages/joint-core/src/mvc/ViewBase.mjs index 5737d60c2..01ed015cb 100644 --- a/packages/joint-core/src/mvc/ViewBase.mjs +++ b/packages/joint-core/src/mvc/ViewBase.mjs @@ -35,7 +35,8 @@ export var ViewBase = function(options) { var delegateEventSplitter = /^(\S+)\s*(.*)$/; // List of view options to be set as properties. -var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events']; +// TODO: `style` attribute is not supported in ViewBase class yet, but only in View class that extends ViewBase. +var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events', 'style']; // Set up all inheritable **ViewBase** properties and methods. assign(ViewBase.prototype, Events, { diff --git a/packages/joint-core/test/jointjs/mvc.view.js b/packages/joint-core/test/jointjs/mvc.view.js index 4343df73c..c17760b65 100644 --- a/packages/joint-core/test/jointjs/mvc.view.js +++ b/packages/joint-core/test/jointjs/mvc.view.js @@ -266,4 +266,23 @@ QUnit.module('joint.mvc.View', function(hooks) { view.remove(); }); }); + + QUnit.module('style', function() { + + QUnit.test('as class property', function(assert) { + assert.expect(1); + var View = joint.mvc.View.extend({ + style: { + 'color': 'red' + } + }); + assert.strictEqual(new View().el.style.color, 'red'); + }); + + QUnit.test('as option', function(assert) { + assert.expect(1); + var View = joint.mvc.View.extend(); + assert.strictEqual(new View({ style: { 'color': 'red' }}).el.style.color, 'red'); + }); + }); });