From 95566400f9bd7380278b28b2805cac3864d6b3a9 Mon Sep 17 00:00:00 2001 From: Max Morgan Date: Wed, 4 Oct 2023 17:37:02 -0400 Subject: [PATCH] Fix shadowdom in Icon --- src/components/atoms/Icon/Icon.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/atoms/Icon/Icon.js b/src/components/atoms/Icon/Icon.js index 2a386526..2b0f65db 100644 --- a/src/components/atoms/Icon/Icon.js +++ b/src/components/atoms/Icon/Icon.js @@ -2,13 +2,16 @@ export default class Icon extends HTMLElement { constructor() { // Always call super first in constructor super(); - // Create a shadow root - // TODO: See CityOfDetroit/detroitmi#1099 - // eslint-disable-next-line no-unused-vars - const shadow = this.attachShadow({ mode: 'open' }); + + // Create a shadow root. + this.attachShadow({ mode: 'open' }); } connectedCallback() { + if (this.isIconConnected()) { + return; + } + // Icon attributes // TODO: See CityOfDetroit/detroitmi#1099 // eslint-disable-next-line prefer-const @@ -39,6 +42,10 @@ export default class Icon extends HTMLElement { this.shadowRoot.appendChild(iconContainer); } + isIconConnected() { + return this.shadowRoot.querySelector('span') !== null; + } + getIcon(icon, size) { switch (icon) { case 'house':