@adamjanicki/ui 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,23 @@
1
1
  import { useEffect } from "react";
2
- var touchEvents = ["touchstart", "touchmove"];
3
- var empty = function () { };
4
2
  var lockScroll = function () {
5
- var bodyStyle = document.body.style;
6
- var bodyOverflow = bodyStyle.overflow;
7
- // set overflow to hidden to prevent scrolling
8
- bodyStyle.overflow = "hidden";
9
- // handle on mobile; prevent touch events
10
- touchEvents.forEach(function (event) {
11
- window.addEventListener(event, empty, { passive: false });
12
- });
3
+ var scrollPosition = window.scrollY;
4
+ var style = document.body.style;
5
+ var htmlStyle = document.documentElement.style;
6
+ var overflow = style.overflow, position = style.position, top = style.top, width = style.width;
7
+ var scrollBehavior = htmlStyle.scrollBehavior;
8
+ htmlStyle.scrollBehavior = "auto";
9
+ style.overflow = "hidden";
10
+ style.position = "fixed";
11
+ style.top = "-".concat(scrollPosition, "px");
12
+ style.width = "100%";
13
13
  return function () {
14
- // restore overflow
15
- if (bodyOverflow) {
16
- bodyStyle.overflow = bodyOverflow;
17
- }
18
- else {
19
- bodyStyle.removeProperty("overflow");
20
- // remove style attribute if empty
21
- if (!bodyStyle.length) {
22
- document.body.removeAttribute("style");
23
- }
24
- }
25
- // remove touch event listeners
26
- touchEvents.forEach(function (event) {
27
- window.removeEventListener(event, empty);
28
- });
14
+ style.overflow = overflow;
15
+ style.position = position;
16
+ style.top = top;
17
+ style.width = width;
18
+ // Restore scroll position without smooth behavior
19
+ window.scrollTo(0, scrollPosition);
20
+ htmlStyle.scrollBehavior = scrollBehavior;
29
21
  };
30
22
  };
31
23
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "Basic UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",