Skip to content

Commit

Permalink
fix(core): preserve static class/styles on root component
Browse files Browse the repository at this point in the history
Fix to preserve statically applied classes and styles on root component while using host binding.

Fixes angular#51460
  • Loading branch information
chintankavathia committed Sep 4, 2024
1 parent 05d0a07 commit 5351b11
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/core/src/render3/node_manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,22 @@ export function setupStaticAttributes(renderer: Renderer, element: RElement, tNo
}

if (classes !== null) {
writeDirectClass(renderer, element, classes);
const elementClasses = element.className.split
? (element.className
.split(' ')
.filter((item) => !classes.includes(item))
.join(' ') ?? '')
: '';
writeDirectClass(renderer, element, `${classes} ${elementClasses}`.trim());
}

if (styles !== null) {
writeDirectStyle(renderer, element, styles);
const elementStyles =
element
.getAttribute('style')
?.split(';')
.filter((item) => !styles.includes(item))
.join(';') ?? '';
writeDirectStyle(renderer, element, `${styles} ${elementStyles}`.trim());
}
}

0 comments on commit 5351b11

Please sign in to comment.