Skip to content

Commit

Permalink
fix(footer): adjustments to adjunct links visibility (#12136)
Browse files Browse the repository at this point in the history
### Related Ticket(s)

[ADCMS-7082](https://jsw.ibm.com/browse/ADCMS-7082)

### Description

Make some adjustments to the logic inside the legal-nav component for adjunct-links visibility. Before the fix here, the `@slotchange` event was not firing as expected when there were no adjunct links to hide them. Further, once the `hidden` class got correctly set on the `adjunct-links` wrapper, needed to fix some Sass to actually hide it.

### Changelog

**Changed**

- Hide adjunct-links container when there are no adjunct links.

<!-- React and Web Component deploy previews are enabled by default. -->
<!-- To enable additional available deploy previews, apply the following -->
<!-- labels for the corresponding package: -->
<!-- *** "test: e2e": Codesandbox examples and e2e integration tests -->
<!-- *** "package: services": Services -->
<!-- *** "package: utilities": Utilities -->
<!-- *** "RTL": React / Web Components (RTL) -->
<!-- *** "feature flag": React / Web Components (experimental) -->
  • Loading branch information
m4olivei committed Nov 29, 2024
1 parent f3db3f7 commit aa88b17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/styles/scss/components/footer/_footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
@include make-container;
}
}
.#{$prefix}--adjunct-links__container--hidden {
.#{$c4d-prefix}--adjunct-links__container--hidden {
display: none;
}
}
Expand Down
46 changes: 26 additions & 20 deletions packages/web-components/src/components/footer/legal-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand All @@ -37,24 +37,22 @@ class C4DLegalNav extends StableSelectorMixin(LitElement) {
*/
@property()
size = FOOTER_SIZE.REGULAR;

/**
* Navigation label for accessibility.
*/
@property()
navLabel = 'Legal Navigation';
/**
* The adjunct links container
*/

@query(`.${c4dPrefix}--adjunct-links__container`)
private _adjunctLinksContainer?: HTMLDivElement;

/**
* The adjunct links slot
*/
@query('[name="adjunct-links"]')
private _adjunctLinksSlot?: HTMLSlotElement;

@state()
protected _hasAdjunctLinks = false;

/**
* Returns a class-name based on the type parameter type
*/
Expand All @@ -65,16 +63,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.
*/
Expand All @@ -88,8 +86,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`
<nav
Expand All @@ -106,8 +110,10 @@ class C4DLegalNav extends StableSelectorMixin(LitElement) {
</div>
<div
part="adjunct-links-container"
class="${c4dPrefix}--adjunct-links__container">
<ul part="adjunct-links-list">
class="${c4dPrefix}--adjunct-links__container${hasAdjunctLinks
? ''
: ` ${c4dPrefix}--adjunct-links__container--hidden`}">
<ul part="adjunct-links-list adjunct-links-list">
<slot
name="adjunct-links"
@slotchange="${this._handleAdjunctLinksVisibility}"></slot>
Expand Down

0 comments on commit aa88b17

Please sign in to comment.