Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
Change inline CSS within shadow DOM custom element

I'm using the lit framework to render my custom model-viewer element with a hidden 'close' button for a faux-fullscreen modal (the modal and close button are meant to only render on iOS). Excluding the unrelated attributes, the element is rendered using:

private [$renderModelViewer]() {
     return html`
       <model-viewer @load=${this[$onModelLoaded]}>
         <div class='modal-close' 
              style="display: none;">X</div>
       </model-viewer>
     `;
   }

In the same file, I have the onModelLoaded function defined as follows:

private [$onModelLoaded](e: CustomEvent) {
     try { 
       if(MODEL_VIEWER_CONSTANTS.IS_IOS) {
        const modalCloseButton = this.renderRoot.querySelectorAll<HTMLElement>('.modal-close') 
        modalCloseButton.forEach(button => {
          button.style.display =`block !important`;
       })
    } catch (err) {
       errorReportingService.reportError(err);
    }
}

Sadly it doesn't seem to update the display of the .modal-close div to display: fixed;, and it stays at display: none;. I've also tried using document.querySelectorAll<HTMLElement>('.modal-close') and this.shadowRoot?.querySelectorAll<HTMLElement>('.modal-close');.

I'm relatively new to lit so admittedly I'm using an odd mish-mash of vanilla js/ts and lit, but I can't seem to figure out how to update the style of the .modal-close div within my <model-viewer> shadowDOM custom element in my html. What am I missing?

EDIT: For a further question, I attempted defining the styles in my css stylesheet linked in my html, but regardless of what I attempted editing the style of an element in the shadow DOM directly in the CSS file (for the .modal-close class for example) never worked. I thought that regardless of it being in the shadow DOM, it is still the same class so the style should work, but apparently not. How could I attempt to do this so I can avoid inline CSS?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda