File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
utilities/scroll-lock-manager Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @shopify/polaris ' : patch
3+ ---
4+
5+ Only apply scroll-lock with scrollbar when body is scrollable
Original file line number Diff line number Diff line change 33 margin : 0 ;
44
55 // stylelint-disable selector-max-attribute
6+ & [data-lock-scrolling-hidden ] {
7+ overflow-y : hidden ;
8+ }
9+
610 [data-lock-scrolling-wrapper ] {
711 overflow : hidden ;
812 height : 100% ;
Original file line number Diff line number Diff line change @@ -2,10 +2,17 @@ import {isServer} from '../target';
22
33export const SCROLL_LOCKING_ATTRIBUTE = 'data-lock-scrolling' ;
44
5+ const SCROLL_LOCKING_HIDDEN_ATTRIBUTE = 'data-lock-scrolling-hidden' ;
6+
57const SCROLL_LOCKING_WRAPPER_ATTRIBUTE = 'data-lock-scrolling-wrapper' ;
68
79let scrollPosition = 0 ;
810
11+ function isScrollBarVisible ( ) {
12+ const { body} = document ;
13+ return body . scrollHeight > body . clientHeight ;
14+ }
15+
916export class ScrollLockManager {
1017 private scrollLocks = 0 ;
1118 private locked = false ;
@@ -29,6 +36,7 @@ export class ScrollLockManager {
2936
3037 if ( scrollLocks === 0 ) {
3138 body . removeAttribute ( SCROLL_LOCKING_ATTRIBUTE ) ;
39+ body . removeAttribute ( SCROLL_LOCKING_HIDDEN_ATTRIBUTE ) ;
3240 if ( wrapper ) {
3341 wrapper . removeAttribute ( SCROLL_LOCKING_WRAPPER_ATTRIBUTE ) ;
3442 }
@@ -38,6 +46,10 @@ export class ScrollLockManager {
3846 scrollPosition = window . pageYOffset ;
3947 body . setAttribute ( SCROLL_LOCKING_ATTRIBUTE , '' ) ;
4048
49+ if ( ! isScrollBarVisible ( ) ) {
50+ body . setAttribute ( SCROLL_LOCKING_HIDDEN_ATTRIBUTE , '' ) ;
51+ }
52+
4153 if ( wrapper ) {
4254 wrapper . setAttribute ( SCROLL_LOCKING_WRAPPER_ATTRIBUTE , '' ) ;
4355 wrapper . scrollTop = scrollPosition ;
You can’t perform that action at this time.
0 commit comments