Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
lit styles when render root is lightdom

So I have the following styles:

  static styles = [css, icons];

Then I set the renderRoot to lightdom:

protected createRenderRoot(): Element | ShadowRoot {
    return this;
}

With this the style is not applied and I have to manually add:

render() {
  return html`
 <style>
       ${css.cssText}
       ${icons.cssText}
 </style>

If I remove the createRenderRoot, the styles work without setting the <style> tag in the render function.

Can anyone tell me what I've done wrong? Or why this is happening?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The default behavior of lit's createRenderRoot is to create a shadow root and add the styles set in the static styles property to said shadow root.

So, when you override createRenderRoot to use this as the root (ergo, not use shadow DOM at all) you are also removing the code that would add the styles too.

The main reason for this is that styles can only be scoped if they're inside shadow DOM. Adding them to a custom element not using shadow DOM would also make those styles apply to any other node that matched the CSS selectors used.

This basically leaves you with two options:

  1. Keep using only light DOM and move your styles to global stylesheets in a CSS file.
  2. Use shadow DOM

More info: https://lit.dev/docs/components/shadow-dom/#implementing-createrenderroot

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda