Skip to content

Commit aab0223

Browse files
committed
fix: make sure to confirm the with/without container exists before running JS logic
1 parent 4c632c5 commit aab0223

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

packages/with-without/js/handleResize.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,42 @@ const handleResize = () => {
2020
const isDesktop = window.matchMedia('(min-width: 1201px)').matches;
2121
const isTablet = !isDesktop && !isMobile;
2222

23-
const slideContentInner = Array.from(
24-
document.querySelectorAll('.c-pega-wwo__content--inner'),
25-
);
2623
const container = document.querySelector('.c-pega-wwo__wrapper');
2724

28-
const activeSlideString = container.classList.contains(
29-
'c-pega-wwo__active-wo',
30-
)
31-
? 'wo'
32-
: 'w';
33-
triggerAnimateInOnInOnlyContent(activeSlideString);
34-
35-
if (isTablet || isMobile) {
36-
const toggleRegionHeight = window.getComputedStyle(
37-
document.querySelector('.c-pega-wwo__title-and-toggle--wrapper'),
38-
).height;
39-
40-
const contents = document.querySelectorAll('.c-pega-wwo__content');
41-
let greatestHeight = 0;
42-
contents.forEach(el => {
43-
const height = parseInt(window.getComputedStyle(el).height, 10);
44-
greatestHeight = height > greatestHeight ? height : greatestHeight;
45-
});
46-
container.style.height = `${greatestHeight +
47-
parseInt(toggleRegionHeight, 10)}px`;
48-
slideContentInner.forEach(el => {
49-
el.style.paddingTop = toggleRegionHeight;
50-
});
51-
} else {
52-
slideContentInner.forEach(el => {
53-
el.style.paddingTop = 0;
54-
});
55-
container.style.height = '100%';
25+
if (container) {
26+
const slideContentInner = Array.from(
27+
document.querySelectorAll('.c-pega-wwo__content--inner'),
28+
);
29+
30+
const activeSlideString = container.classList.contains(
31+
'c-pega-wwo__active-wo',
32+
)
33+
? 'wo'
34+
: 'w';
35+
triggerAnimateInOnInOnlyContent(activeSlideString);
36+
37+
if (isTablet || isMobile) {
38+
const toggleRegionHeight = window.getComputedStyle(
39+
document.querySelector('.c-pega-wwo__title-and-toggle--wrapper'),
40+
).height;
41+
42+
const contents = document.querySelectorAll('.c-pega-wwo__content');
43+
let greatestHeight = 0;
44+
contents.forEach(el => {
45+
const height = parseInt(window.getComputedStyle(el).height, 10);
46+
greatestHeight = height > greatestHeight ? height : greatestHeight;
47+
});
48+
container.style.height = `${greatestHeight +
49+
parseInt(toggleRegionHeight, 10)}px`;
50+
slideContentInner.forEach(el => {
51+
el.style.paddingTop = toggleRegionHeight;
52+
});
53+
} else {
54+
slideContentInner.forEach(el => {
55+
el.style.paddingTop = 0;
56+
});
57+
container.style.height = '100%';
58+
}
5659
}
5760
};
5861

0 commit comments

Comments
 (0)