mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #648 - Style attribute object and lengths not handled properly
This commit is contained in:
parent
47d3fc36cb
commit
a7501d1190
@ -93,13 +93,18 @@ exports.sa = function(style) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (typeof style === 'string') {
|
||||
var type = typeof style;
|
||||
|
||||
if (type === 'string') {
|
||||
return attrHelper(STYLE_ATTR, style, false);
|
||||
} else if (typeof style === 'object') {
|
||||
} else if (type === 'object') {
|
||||
var styles = '';
|
||||
for (var name in style) {
|
||||
var value = style[name];
|
||||
if (value != null) {
|
||||
if (typeof value === 'number' && value) {
|
||||
value += 'px';
|
||||
}
|
||||
var nameDashed = dashedNames[name];
|
||||
if (!nameDashed) {
|
||||
nameDashed = dashedNames[name] = name.replace(/([A-Z])/g, '-$1').toLowerCase();
|
||||
@ -164,4 +169,4 @@ function classList(arg) {
|
||||
|
||||
var commonHelpers = require('../helpers');
|
||||
extend(exports, commonHelpers);
|
||||
exports.cl = classList;
|
||||
exports.cl = classList;
|
||||
|
||||
@ -10,13 +10,19 @@ module.exports = function(style) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof style === 'string') {
|
||||
var type = typeof style;
|
||||
|
||||
if (type === 'string') {
|
||||
return style;
|
||||
} else if (typeof style === 'object') {
|
||||
} else if (type === 'object') {
|
||||
var styles = '';
|
||||
for (var name in style) {
|
||||
var value = style[name];
|
||||
if (value) {
|
||||
if (value != null) {
|
||||
if (typeof value === 'number' && value) {
|
||||
value += 'px';
|
||||
}
|
||||
|
||||
var nameDashed = dashedNames[name];
|
||||
if (!nameDashed) {
|
||||
nameDashed = dashedNames[name] = name.replace(/([A-Z])/g, '-$1').toLowerCase();
|
||||
@ -28,4 +34,4 @@ module.exports = function(style) {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
5
test/autotests/components-browser/style-attr/index.marko
Normal file
5
test/autotests/components-browser/style-attr/index.marko
Normal file
@ -0,0 +1,5 @@
|
||||
class {}
|
||||
$ var marginRight = 10;
|
||||
$ var left = 0;
|
||||
|
||||
<div style={left: left, marginRight: marginRight}></div>
|
||||
7
test/autotests/components-browser/style-attr/test.js
Normal file
7
test/autotests/components-browser/style-attr/test.js
Normal file
@ -0,0 +1,7 @@
|
||||
var expect = require('chai').expect;
|
||||
|
||||
module.exports = function(helpers) {
|
||||
var component = helpers.mount(require('./index'), {});
|
||||
expect(component.el.style.left).to.equal('0px');
|
||||
expect(component.el.style.marginRight).to.equal('10px');
|
||||
};
|
||||
@ -0,0 +1 @@
|
||||
<div style="left:0;margin-right:10px;"></div>
|
||||
@ -0,0 +1 @@
|
||||
div style={left: 0, marginRight: 10}
|
||||
1
test/autotests/render/style-attr-object-units/test.js
Normal file
1
test/autotests/render/style-attr-object-units/test.js
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user