Skip to content

Commit f047d75

Browse files
Content below Sky Nav animates again (#1986)
1 parent e5af776 commit f047d75

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

.changeset/flat-points-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
Fix bug where content below Sky Nav was not animating open/closed

src/components/sky-nav/sky-nav.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ export const initSkyNav = (navButton: HTMLButtonElement) => {
5757
return;
5858
}
5959

60-
// We need to keep track of the siblings after the menu,
61-
// because we will push them down for the animation
62-
const elementsToShift: HTMLElement[] = [navWrapper];
63-
let sibling: HTMLElement | null = navWrapper;
64-
// eslint-disable-next-line no-unmodified-loop-condition
65-
while ((sibling = sibling.nextElementSibling as HTMLElement | null)) {
66-
elementsToShift.push(sibling);
67-
}
68-
6960
const duration = Number.parseFloat(tokens.time.transition.slow.value);
7061
const transition = `transform ${duration}s ${tokens.ease.in_out.value}`;
7162
clearTimeout(timeoutId);
@@ -74,34 +65,31 @@ export const initSkyNav = (navButton: HTMLButtonElement) => {
7465
const heightDiff = menu.getBoundingClientRect().height;
7566
if (isExpanded) {
7667
// Closing menu: slide the elements up before hiding the menu
77-
for (const el of elementsToShift) {
78-
el.style.transition = transition;
79-
el.style.transform = `translateY(${-heightDiff}px)`;
80-
}
68+
document.body.style.setProperty('transition', transition);
69+
document.body.style.setProperty(
70+
'transform',
71+
`translateY(${-heightDiff}px)`
72+
);
8173

8274
timeoutId = setTimeout(() => {
8375
menu.hidden = true;
84-
for (const el of elementsToShift) {
85-
el.style.transition = '';
86-
el.style.transform = '';
87-
}
76+
document.body.style.removeProperty('transition');
77+
document.body.style.removeProperty('transform');
8878
}, duration * 1000) as any as number;
8979
} else {
9080
// Opening menu: start the elements higher than their "resting position" and then slide them down
91-
for (const el of elementsToShift)
92-
el.style.transform = `translateY(${-heightDiff}px)`;
81+
document.body.style.setProperty(
82+
'transform',
83+
`translateY(${-heightDiff}px)`
84+
);
9385

9486
// Flush changes to the DOM
9587
// eslint-disable-next-line @cloudfour/typescript-eslint/no-unused-expressions, mdx/no-unused-expressions
9688
navWrapper.offsetWidth;
97-
for (const el of elementsToShift) {
98-
el.style.transition = transition;
99-
el.style.transform = '';
100-
}
89+
document.body.style.setProperty('transition', transition);
90+
document.body.style.removeProperty('transform');
10191
timeoutId = setTimeout(() => {
102-
for (const el of elementsToShift) {
103-
el.style.transition = '';
104-
}
92+
document.body.style.removeProperty('transition');
10593
}, duration * 1000) as any as number;
10694
}
10795
};

src/components/sky-nav/sky-nav.twig

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,31 @@
106106
@see https://github.com/twigjs/twig.js/issues/262
107107
#}
108108
{% if include_main_demo %}
109-
<main class="o-container o-container--pad" id="{{ main_id }}">
110-
<div class="o-container__content">
111-
<p>Hello world! This is the main content.</p>
109+
<main id="main" class="o-page__content" style="">
110+
<div class="c-cloud-cover t-dark">
111+
<div class="o-container o-container--pad-inline">
112+
<div class="o-container__content c-cloud-cover__inner">
113+
<div class="c-cloud-cover__content">
114+
<div class="o-rhythm o-rhythm--condensed">
115+
<div class="c-cloud-cover__heading">
116+
<h1 class="c-heading c-heading--level-n2">
117+
Team
118+
</h1>
119+
</div>
120+
<div class="c-cloud-cover__copy">
121+
<div class="o-rhythm">
122+
Teamwork makes the dream work
123+
</div>
124+
</div>
125+
</div>
126+
</div>
127+
</div>
128+
</div>
129+
</div>
130+
<div class="o-container o-container--pad">
131+
<div class="o-container__content">
132+
<p>This is some content.</p>
133+
</div>
112134
</div>
113135
</main>
114136
{% endif %}

0 commit comments

Comments
 (0)