Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/quiet-coats-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Only apply scroll-lock with scrollbar when body is scrollable
4 changes: 4 additions & 0 deletions polaris-react/src/components/ScrollLock/ScrollLock.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
margin: 0;

// stylelint-disable selector-max-attribute
&[data-lock-scrolling-hidden] {
overflow-y: hidden;
}

[data-lock-scrolling-wrapper] {
overflow: hidden;
height: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ import {isServer} from '../target';

export const SCROLL_LOCKING_ATTRIBUTE = 'data-lock-scrolling';

const SCROLL_LOCKING_HIDDEN_ATTRIBUTE = 'data-lock-scrolling-hidden';

const SCROLL_LOCKING_WRAPPER_ATTRIBUTE = 'data-lock-scrolling-wrapper';

let scrollPosition = 0;

function isScrollBarVisible() {
const {body} = document;
return body.scrollHeight > body.clientHeight;
}

export class ScrollLockManager {
private scrollLocks = 0;
private locked = false;
Expand All @@ -29,6 +36,7 @@ export class ScrollLockManager {

if (scrollLocks === 0) {
body.removeAttribute(SCROLL_LOCKING_ATTRIBUTE);
body.removeAttribute(SCROLL_LOCKING_HIDDEN_ATTRIBUTE);
if (wrapper) {
wrapper.removeAttribute(SCROLL_LOCKING_WRAPPER_ATTRIBUTE);
}
Expand All @@ -38,6 +46,10 @@ export class ScrollLockManager {
scrollPosition = window.pageYOffset;
body.setAttribute(SCROLL_LOCKING_ATTRIBUTE, '');

if (!isScrollBarVisible()) {
body.setAttribute(SCROLL_LOCKING_HIDDEN_ATTRIBUTE, '');
}

if (wrapper) {
wrapper.setAttribute(SCROLL_LOCKING_WRAPPER_ATTRIBUTE, '');
wrapper.scrollTop = scrollPosition;
Expand Down