Created
April 17, 2025 14:37
-
-
Save heyMP/c57834b2bcf56425a3d93f74a91aad6e to your computer and use it in GitHub Desktop.
Inject Styles into Lit component with Constructible Stylesheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before we add our component to the DOM | |
// we are going to alter the rh-cta definition | |
// this will alter the stylesheet for all CTAs | |
await customElements.whenDefined('rh-cta').then(() => { | |
const RhCta = customElements.get('rh-cta'); | |
if (!RhCta) { return; } | |
const styles = RhCta.styles?.[0].styleSheet as CSSStyleSheet; | |
styles.insertRule(` | |
::slotted(a) { white-space: normal !important; } | |
`, styles.cssRules.length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment