From 70552f17180f425d8f9ba8cef483debe5434738f Mon Sep 17 00:00:00 2001 From: Matthew Oliveira Date: Fri, 29 Nov 2024 14:25:53 -0500 Subject: [PATCH 1/3] fix(footer): adjustments to adjunct links visibility --- .../scss/components/footer/_footer.scss | 4 +- .../src/components/footer/legal-nav.ts | 39 ++++++++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/styles/scss/components/footer/_footer.scss b/packages/styles/scss/components/footer/_footer.scss index 6067cc52356..476951558bc 100644 --- a/packages/styles/scss/components/footer/_footer.scss +++ b/packages/styles/scss/components/footer/_footer.scss @@ -1,5 +1,5 @@ /** - * Copyright IBM Corp. 2016, 2023 + * Copyright IBM Corp. 2016, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -220,7 +220,7 @@ @include make-container; } } - .#{$prefix}--adjunct-links__container--hidden { + .#{$c4d-prefix}--adjunct-links__container--hidden { display: none; } } diff --git a/packages/web-components/src/components/footer/legal-nav.ts b/packages/web-components/src/components/footer/legal-nav.ts index 23b8b93ee6e..b76ca19e502 100644 --- a/packages/web-components/src/components/footer/legal-nav.ts +++ b/packages/web-components/src/components/footer/legal-nav.ts @@ -8,7 +8,7 @@ */ import { LitElement, html } from 'lit'; -import { property, query } from 'lit/decorators.js'; +import { property, query, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import settings from '@carbon/ibmdotcom-utilities/es/utilities/settings/settings.js'; @@ -17,7 +17,7 @@ import StableSelectorMixin from '../../globals/mixins/stable-selector'; import styles from './footer.scss'; import { carbonElement as customElement } from '@carbon/web-components/es/globals/decorators/carbon-element.js'; -const { prefix, stablePrefix: c4dPrefix } = settings; +const { stablePrefix: c4dPrefix } = settings; /** * Legal nav. @@ -55,6 +55,9 @@ class C4DLegalNav extends StableSelectorMixin(LitElement) { @query('[name="adjunct-links"]') private _adjunctLinksSlot?: HTMLSlotElement; + @state() + protected _hasAdjunctLinks = false; + /** * Returns a class-name based on the type parameter type */ @@ -65,16 +68,16 @@ class C4DLegalNav extends StableSelectorMixin(LitElement) { }); } - protected _handleAdjunctLinksVisibility() { - const { - _adjunctLinksContainer: adjunctLinksContainer, - _adjunctLinksSlot: adjunctLinksSlot, - } = this; + /** + * Handles slot change event of adjunct-links slot to track if there are any. + */ + protected _handleAdjunctLinksVisibility = () => { + const { _adjunctLinksSlot: adjunctLinksSlot } = this; + + this._hasAdjunctLinks = + (adjunctLinksSlot?.assignedNodes().length || 0) !== 0; + }; - const hiddenClass = `${prefix}--adjunct-links__container--hidden`; - const isEmpty = (adjunctLinksSlot?.assignedNodes().length || 0) === 0; - adjunctLinksContainer?.classList.toggle(hiddenClass, isEmpty); - } /** * The shadow slot this legal nav should be in. */ @@ -88,8 +91,14 @@ class C4DLegalNav extends StableSelectorMixin(LitElement) { super.connectedCallback(); } + firstUpdated() { + const { _adjunctLinksSlot: adjunctLinksSlot } = this; + this._hasAdjunctLinks = + (adjunctLinksSlot?.assignedNodes().length || 0) !== 0; + } + render() { - const { navLabel } = this; + const { navLabel, _hasAdjunctLinks: hasAdjunctLinks } = this; return this.size !== FOOTER_SIZE.MICRO ? html`