diff --git a/lib/src/utils/domUtils.ts b/lib/src/utils/domUtils.ts index e5ff37d1a..8c80bcbaf 100644 --- a/lib/src/utils/domUtils.ts +++ b/lib/src/utils/domUtils.ts @@ -99,7 +99,7 @@ export function createDomStructure(item: HtmlStruct, appendToElm?: HTMLElement, delete item.props.innerHTML; } - const elm = createDomElement(item.tagName, objectRemoveEmptyProps(item.props), appendToElm); + const elm = createDomElement(item.tagName, objectRemoveEmptyProps(item.props, ['class', 'title', 'style']), appendToElm); let parent: HTMLElement | null | undefined = parentElm; if (!parent) { parent = elm; diff --git a/lib/src/utils/utils.ts b/lib/src/utils/utils.ts index e5417a448..ab969d5d5 100644 --- a/lib/src/utils/utils.ts +++ b/lib/src/utils/utils.ts @@ -54,8 +54,20 @@ export function isDefined(val: any) { return val !== undefined && val !== null && val !== ''; } -export function objectRemoveEmptyProps(obj: any) { +/** + * Remove all empty props from an object, + * we can optionally provide a fixed list of props to consider for removal (anything else will be excluded) + * @param {*} obj + * @param {Array} [clearProps] - optional list of props to consider for removal (anything else will be excluded) + * @returns cleaned object + */ +export function objectRemoveEmptyProps(obj: any, clearProps?: string[]) { if (typeof obj === 'object') { + if (clearProps) { + return Object.fromEntries( + Object.entries(obj).filter(([name, val]) => (!isDefined(val) && !clearProps.includes(name)) || isDefined(val)) + ); + } return Object.fromEntries(Object.entries(obj).filter(([_, v]) => isDefined(v))); } return obj;