Skip to content

Commit

Permalink
framework/element: add support of className property
Browse files Browse the repository at this point in the history
Resolves #35
  • Loading branch information
OleksiyRudenko committed May 18, 2021
1 parent 74ba98c commit 13576f7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/framework/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ export const createElement = (tag, props, ...children) => {
// https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute#example
if (['disabled', 'checked'].includes(name) && !value) {
element.removeAttribute(name);
} else if (name.toLowerCase() === 'classname') {
// We want to treat both strings and arrays in a similar manner
const classList = typeof value === 'string' ? value.split(' ').filter(Boolean) : value;
element.classList.add(...classList);
} else {
element.setAttribute(name, value);
element.setAttribute(
name,
/** @type {string} */
value,
);
}
}
} catch (e) {
Expand Down

0 comments on commit 13576f7

Please sign in to comment.