Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mega-menu): Mega menu content position fix - FRONT-4606 #3615

Merged
merged 14 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,17 @@ const prepareData = (data, args) => {

export default {
title: 'Components/Site-wide/Site header',
decorators: [withNotes, withCode],
decorators: [
withNotes,
withCode,
(storyFn) => {
document.body.style.position = 'fixed';
document.body.style.width = '100%';
document.body.style.overflowY = 'scroll';

return storyFn();
},
],
parameters: { layout: 'fullscreen' },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,17 @@ const prepareData = (data, args) => {

export default {
title: 'Components/Site-wide/Site header',
decorators: [withNotes, withCode],
decorators: [
withNotes,
withCode,
(storyFn) => {
document.body.style.position = 'fixed';
document.body.style.width = '100%';
document.body.style.overflowY = 'scroll';

return storyFn();
},
],
parameters: { layout: 'fullscreen' },
};

Expand Down
36 changes: 16 additions & 20 deletions src/implementations/vanilla/components/mega-menu/mega-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ export class MegaMenu {
this.links = null;
this.isOpen = false;
this.resizeTimer = null;
this.wrappers = null;
this.isKeyEvent = false;
this.isDesktop = false;
this.isLarge = false;
this.lastVisibleItem = null;
this.menuOverlay = null;
this.currentItem = null;
this.totalItemsWidth = 0;
this.breakpointL = 996;
Expand Down Expand Up @@ -185,11 +187,13 @@ export class MegaMenu {
this.links = queryAll(this.linkSelector, this.element);
this.header = queryOne('.ecl-site-header', document);
this.headerBanner = queryOne('.ecl-site-header__banner', document);
this.wrappers = queryAll('.ecl-mega-menu__wrapper', this.element);
this.headerNotification = queryOne(
'.ecl-site-header__notification',
document,
);
this.toggleLabel = queryOne('.ecl-button__label', this.open);
this.menuOverlay = queryOne('.ecl-mega-menu__overlay', this.element);

// Check if we should use desktop display (it does not rely only on breakpoints)
this.isDesktop = this.useDesktopDisplay();
Expand Down Expand Up @@ -440,18 +444,14 @@ export class MegaMenu {
* Disable page scrolling
*/
disableScroll() {
const scrollBarWidth =
window.innerWidth - document.documentElement.clientWidth;
document.body.classList.add('ecl-mega-menu-prevent-scroll');
document.body.style.paddingRight = `${scrollBarWidth}px`;
}

/**
* Enable page scrolling
*/
enableScroll() {
document.body.classList.remove('ecl-mega-menu-prevent-scroll');
document.body.style.paddingRight = '';
}

/**
Expand Down Expand Up @@ -501,9 +501,8 @@ export class MegaMenu {
});

// Reset top position and height of the wrappers
const wrappers = queryAll('.ecl-mega-menu__wrapper', this.element);
if (wrappers) {
wrappers.forEach((wrapper) => {
if (this.wrappers) {
this.wrappers.forEach((wrapper) => {
wrapper.style.top = '';
wrapper.style.height = '';
});
Expand Down Expand Up @@ -790,7 +789,6 @@ export class MegaMenu {
* Dinamically set the position of the menu overlay
*/
positionMenuOverlay() {
const menuOverlay = queryOne('.ecl-mega-menu__overlay', this.element);
let availableHeight = 0;
if (!this.isDesktop) {
// In mobile, we get the bottom position of the site header header
Expand All @@ -799,8 +797,8 @@ export class MegaMenu {
const position = this.header.getBoundingClientRect();
const bottomPosition = Math.round(position.bottom);

if (menuOverlay) {
menuOverlay.style.top = `${bottomPosition}px`;
if (this.menuOverlay) {
this.menuOverlay.style.top = `${bottomPosition}px`;
}
if (this.inner) {
this.inner.style.top = `${bottomPosition}px`;
Expand Down Expand Up @@ -842,9 +840,8 @@ export class MegaMenu {
}
}
}
const wrappers = queryAll('.ecl-mega-menu__wrapper', this.element);
if (wrappers) {
wrappers.forEach((wrapper) => {
if (this.wrappers) {
this.wrappers.forEach((wrapper) => {
wrapper.style.top = '';
wrapper.style.height = '';
});
Expand All @@ -861,20 +858,19 @@ export class MegaMenu {
const item = queryOne(this.itemSelector, this.element);
const rect = item.getBoundingClientRect();
const rectHeight = rect.height;
const wrappers = queryAll('.ecl-mega-menu__wrapper', this.element);

if (wrappers) {
wrappers.forEach((wrapper) => {
if (this.wrappers) {
this.wrappers.forEach((wrapper) => {
wrapper.style.top = `${rectHeight}px`;
});
}
if (menuOverlay) {
menuOverlay.style.top = `${headerBottom}px`;
if (this.menuOverlay) {
this.menuOverlay.style.top = `${headerBottom}px`;
}
} else {
const bottomPosition = this.element.getBoundingClientRect().bottom;
if (menuOverlay) {
menuOverlay.style.top = `${bottomPosition}px`;
if (this.menuOverlay) {
this.menuOverlay.style.top = `${bottomPosition}px`;
}
}
}, 0);
Expand Down
17 changes: 4 additions & 13 deletions src/implementations/vanilla/components/mega-menu/mega-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,9 @@ $mega-menu: null !default;
color: map.get($mega-menu, 'mobile', 'item-color');
padding: map.get($mega-menu, 'mobile', 'subitem-padding');
position: relative;
display: -webkit-box;
line-height: map.get($theme, 'line-height-ui', 'xs');
min-height: 42px;
text-align: left;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-align: initial;
width: 100%;

&.ecl-link--icon:not(.ecl-mega-menu__parent-link) {
Expand All @@ -821,13 +817,6 @@ $mega-menu: null !default;
height: calc(var(--s-s) + 0.5px);
padding: 1px 3px;
}

.ecl-link__label {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
}

&:hover {
Expand Down Expand Up @@ -1407,5 +1396,7 @@ $mega-menu: null !default;
}

.ecl-mega-menu-prevent-scroll {
overflow: hidden;
position: fixed;
overflow-y: scroll;
width: 100%;
}
Loading