Skip to content

Commit c6bc429

Browse files
committed
style & className attrs should work together
1 parent 9adbb3b commit c6bc429

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/builder.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ function processAttrs(attrs) {
122122
/* eslint-disable no-param-reassign */
123123
attrs.className = processClassName(attrs.className);
124124
/* eslint-enable no-param-reassign */
125-
} else if (attrs.style && typeof attrs.style === 'object') {
125+
}
126+
if (attrs.style && typeof attrs.style === 'object') {
126127
attrs.style = processStyleObject(attrs.style);
127-
} else if (attrs.onenter && attrs.onkeyup || attrs.onEnter && attrs.onKeyUp) {
128+
}
129+
if (attrs.onenter && attrs.onkeyup || attrs.onEnter && attrs.onKeyUp) {
128130
throw new Error('onenter and onkeyup are mutually exclusive, consider adding a switch statement to your onkeyup handler for the enter case.');
129131
}
130132

test/builder_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ describe('Nomplate ElementBuilder', () => {
5959
assert.equal(root.firstChild.textContent, '');
6060
});
6161

62+
it('handles className and style attrs', () => {
63+
const root = builder('div', () => {
64+
builder('div', {className: 'abcd', style: {color: 'blue'}}, 'hello');
65+
});
66+
67+
assert.equal(root.nodeName, 'div');
68+
const child = root.firstChild;
69+
assert.equal(child.nodeName, 'div');
70+
assert.equal(child.className, 'abcd');
71+
assert.equal(child.attrs.style, 'color:blue;');
72+
});
73+
6274
it('resets the stack, even on error', () => {
6375
try {
6476
builder('div', () => {

0 commit comments

Comments
 (0)