Skip to content

Commit f9ee260

Browse files
committed
Fix #3 empty css class
1 parent bcdaf5f commit f9ee260

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function handleClassList(node, arg, placeholder) {
127127
});
128128
return;
129129
}
130-
node.classList.add(arg);
130+
if(arg) node.classList.add(arg);
131131
node.classList.remove(placeholder);
132132
}
133133

src/html.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,16 @@ test("Splicing in undefined as value should work", () => {
197197
`;
198198
expect(elements.filter(el => el instanceof HTMLElement).length).toBe(2);
199199
});
200+
201+
test("Applying empty class should work", () => {
202+
const elements = html`
203+
<div class="${""}">
204+
<h1>Yeah</h1>
205+
</div>
206+
<div class="${undefined}">
207+
<h2>Uuuuh</h2>
208+
</div>
209+
`;
210+
expect(elements.filter(el => el instanceof HTMLElement).at(0).classList.length).toBe(0);
211+
expect(elements.filter(el => el instanceof HTMLElement).at(1).classList.length).toBe(0);
212+
})

0 commit comments

Comments
 (0)