Skip to content

Commit 4bbe3cc

Browse files
authored
fix(sticky-header): report cumulative height before first scroll (#10843)
* fix(sticky-header): calculate height when setting elements * fix(sticky-header): update snapshots
1 parent 16ebb55 commit 4bbe3cc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/utilities/src/utilities/StickyHeader/StickyHeader.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class StickyHeader {
103103
if (this._masthead) {
104104
this._masthead.setAttribute('with-banner', '');
105105
}
106+
107+
this._calculateCumulativeHeight();
106108
}
107109
}
108110

@@ -121,12 +123,14 @@ class StickyHeader {
121123
this._leadspaceWithSearchStickyThreshold =
122124
parseInt(window.getComputedStyle(leadspaceSearchBar).paddingBottom) -
123125
16;
126+
this._calculateCumulativeHeight();
124127
}
125128
}
126129

127130
set localeModal(component) {
128131
if (this._validateComponent(component, `${ddsPrefix}-locale-modal`)) {
129132
this._localeModal = component;
133+
this._calculateCumulativeHeight();
130134
}
131135
}
132136

@@ -139,6 +143,7 @@ class StickyHeader {
139143
`.${prefix}--masthead__l0`
140144
);
141145
this._mastheadL1 = component.querySelector(`${ddsPrefix}-masthead-l1`);
146+
this._calculateCumulativeHeight();
142147
}
143148
}
144149

@@ -147,6 +152,7 @@ class StickyHeader {
147152
this._tableOfContents = component;
148153
this._tableOfContentsStickyUpdate();
149154
this._resizeObserver.observe(this._tableOfContents);
155+
this._calculateCumulativeHeight();
150156
}
151157
}
152158

@@ -156,7 +162,7 @@ class StickyHeader {
156162
_throttledHandler() {
157163
if (!this._throttled) {
158164
this._throttled = true;
159-
this._handleScroll();
165+
this._calculateCumulativeHeight();
160166

161167
setTimeout(() => {
162168
this._throttled = false;
@@ -188,7 +194,7 @@ class StickyHeader {
188194
tocInner.style.top = `${masthead.offsetHeight}px`;
189195
}
190196
}
191-
this._handleScroll();
197+
this._calculateCumulativeHeight();
192198
}
193199

194200
if (leadspaceSearchBar) {
@@ -198,7 +204,7 @@ class StickyHeader {
198204
}
199205
}
200206

201-
_handleScroll() {
207+
_calculateCumulativeHeight() {
202208
const {
203209
_lastScrollPosition: oldY,
204210
_banner: banner,

packages/web-components/tests/snapshots/dds-table-of-contents.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<div
1010
class="bx--tableofcontents__sidebar"
1111
part="table"
12+
style="transition: none 0s ease 0s; top: 0px;"
1213
>
1314
<div
1415
class="bx--tableofcontents__desktop__children"
@@ -66,6 +67,7 @@
6667
<div
6768
class="bx--tableofcontents__sidebar"
6869
part="table"
70+
style="transition: none 0s ease 0s; top: 0px;"
6971
>
7072
<div class="bx--tableofcontents__desktop__children">
7173
<slot name="heading">
@@ -120,6 +122,7 @@
120122
<div
121123
class="bx--tableofcontents__sidebar"
122124
part="table"
125+
style="transition: none 0s ease 0s; top: 0px;"
123126
>
124127
<div class="bx--tableofcontents__mobile-top">
125128
</div>

0 commit comments

Comments
 (0)