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(core, modal): décalage scrollbar à l'ouverture/fermeture modale & fix scroll behavior [DS-3048,DS-3054] #519

Merged
merged 10 commits into from
Jun 19, 2023
1 change: 1 addition & 0 deletions src/component/modal/style/_module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@include margin(0);
@include display-flex(column, stretch, space-between);
@include fixed(0, 0, 0, 0, 100%, 100%);
@include padding-right(var(--scrollbar-width));
// transition in/out
transition: opacity 0.3s, visibility 0.3s;

Expand Down
12 changes: 10 additions & 2 deletions src/core/script/api/modules/scroll/scroll-locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ class ScrollLocker extends Module {
if (!this._isLocked) {
this._isLocked = true;
this._scrollY = window.scrollY;
const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;
document.documentElement.setAttribute(ns.attr('scrolling'), 'false');
document.body.style.top = `${this._scrollY * -1}px`;
document.body.style.top = `${-this._scrollY}px`;
this.behavior = getComputedStyle(document.documentElement).getPropertyValue('scroll-behavior');
if (this.behavior === 'smooth') document.documentElement.style.scrollBehavior = 'auto';
if (scrollBarGap > 0) {
document.documentElement.style.setProperty('--scrollbar-width', `${scrollBarGap}px`);
}
}
}

Expand All @@ -29,13 +35,15 @@ class ScrollLocker extends Module {
document.documentElement.removeAttribute(ns.attr('scrolling'));
document.body.style.top = '';
window.scrollTo(0, this._scrollY);
if (this.behavior === 'smooth') document.documentElement.style.removeProperty('scroll-behavior');
document.documentElement.style.removeProperty('--scrollbar-width');
}
}

move (value) {
if (this._isLocked) {
this._scrollY += value;
document.body.style.top = `${this._scrollY * -1}px`;
document.body.style.top = `${-this._scrollY}px`;
} else {
window.scrollTo(0, window.scrollY + value);
}
Expand Down
23 changes: 15 additions & 8 deletions src/core/style/display/module/_no-scroll.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
/**
* Fixe le scroll en arrière plan
*/
// TODO: transformer en attribut ?
:root#{ns-attr(scrolling)} body {
overflow: hidden;
bottom: 0;
left: 0;
position: fixed;
right: 0;
top: 0;
:root {
--scrollbar-width: 0;

body {
border-right: var(--scrollbar-width) solid transparent;
}

&#{ns-attr(scrolling)} body {
overflow: hidden;
bottom: 0;
left: 0;
position: fixed;
right: 0;
top: 0;
}
}