Skip to content

Commit 6208871

Browse files
authored
Merge pull request #682 from lumapps/chore/update-disable-body-scroll
fix(modal): fix unexpected scroll to top on dialog/lightbox open
2 parents 3ec4060 + 180459e commit 6208871

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Icon: Add missing class to style svg correctly
13+
- Dialog/Lightbox: Fix unexpected scroll to top when opening a dialog or lightbox.
1314

1415
## [1.0.19][] - 2021-07-15
1516

packages/lumx-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@lumx/core": "^1.0.19",
1111
"@lumx/icons": "^1.0.19",
1212
"@popperjs/core": "^2.5.4",
13-
"body-scroll-lock": "^2.6.4",
13+
"body-scroll-lock": "^3.1.5",
1414
"classnames": "^2.2.6",
1515
"react-is": "^16.13.0",
1616
"react-popper": "^2.2.4",

packages/lumx-react/src/hooks/useDisableBodyScroll.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ export const useDisableBodyScroll = (modalElement: Element | Falsy): void => {
77
if (!modalElement) {
88
return undefined;
99
}
10+
// Fixing the document overflow style to prevent a bug that scrolls the window to the top.
11+
const previousDocumentOverflow = document.documentElement.style.overflow;
12+
document.documentElement.style.overflow = 'visible';
1013
disableBodyScroll(modalElement);
11-
return () => enableBodyScroll(modalElement);
14+
return () => {
15+
enableBodyScroll(modalElement);
16+
// Restore the previous overflow style.
17+
document.documentElement.style.overflow = previousDocumentOverflow;
18+
};
1219
}, [modalElement]);
1320
};

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8061,10 +8061,10 @@ [email protected], body-parser@^1.19.0:
80618061
raw-body "2.4.0"
80628062
type-is "~1.6.17"
80638063

8064-
body-scroll-lock@^2.6.4:
8065-
version "2.6.4"
8066-
resolved "https://registry.yarnpkg.com/body-scroll-lock/-/body-scroll-lock-2.6.4.tgz#567abc60ef4d656a79156781771398ef40462e94"
8067-
integrity sha512-NP08WsovlmxEoZP9pdlqrE+AhNaivlTrz9a0FF37BQsnOrpN48eNqivKkE7SYpM9N+YIPjsdVzfLAUQDBm6OQw==
8064+
body-scroll-lock@^3.1.5:
8065+
version "3.1.5"
8066+
resolved "https://registry.yarnpkg.com/body-scroll-lock/-/body-scroll-lock-3.1.5.tgz#c1392d9217ed2c3e237fee1e910f6cdd80b7aaec"
8067+
integrity sha512-Yi1Xaml0EvNA0OYWxXiYNqY24AfWkbA6w5vxE7GWxtKfzIbZM+Qw+aSmkgsbWzbHiy/RCSkUZBplVxTA+E4jJg==
80688068

80698069
bonjour@^3.5.0:
80708070
version "3.5.0"

0 commit comments

Comments
 (0)