@tp3/chat-widget 0.1.11 → 0.1.12

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.
@@ -66,14 +66,26 @@ function ChatWidget({
66
66
  const inputRef = (0, import_react.useRef)(null);
67
67
  const typewriterQueue = (0, import_react.useRef)([]);
68
68
  const typewriterTimer = (0, import_react.useRef)(null);
69
+ const savedScrollY = (0, import_react.useRef)(0);
69
70
  (0, import_react.useEffect)(() => {
70
71
  if (open && !closing) {
71
- document.documentElement.style.overflow = "hidden";
72
+ savedScrollY.current = window.scrollY;
73
+ document.body.style.position = "fixed";
74
+ document.body.style.top = `-${savedScrollY.current}px`;
75
+ document.body.style.left = "0";
76
+ document.body.style.right = "0";
72
77
  } else {
73
- document.documentElement.style.overflow = "";
78
+ document.body.style.position = "";
79
+ document.body.style.top = "";
80
+ document.body.style.left = "";
81
+ document.body.style.right = "";
82
+ window.scrollTo(0, savedScrollY.current);
74
83
  }
75
84
  return () => {
76
- document.documentElement.style.overflow = "";
85
+ document.body.style.position = "";
86
+ document.body.style.top = "";
87
+ document.body.style.left = "";
88
+ document.body.style.right = "";
77
89
  };
78
90
  }, [open, closing]);
79
91
  (0, import_react.useEffect)(() => {
@@ -42,14 +42,26 @@ function ChatWidget({
42
42
  const inputRef = useRef(null);
43
43
  const typewriterQueue = useRef([]);
44
44
  const typewriterTimer = useRef(null);
45
+ const savedScrollY = useRef(0);
45
46
  useEffect(() => {
46
47
  if (open && !closing) {
47
- document.documentElement.style.overflow = "hidden";
48
+ savedScrollY.current = window.scrollY;
49
+ document.body.style.position = "fixed";
50
+ document.body.style.top = `-${savedScrollY.current}px`;
51
+ document.body.style.left = "0";
52
+ document.body.style.right = "0";
48
53
  } else {
49
- document.documentElement.style.overflow = "";
54
+ document.body.style.position = "";
55
+ document.body.style.top = "";
56
+ document.body.style.left = "";
57
+ document.body.style.right = "";
58
+ window.scrollTo(0, savedScrollY.current);
50
59
  }
51
60
  return () => {
52
- document.documentElement.style.overflow = "";
61
+ document.body.style.position = "";
62
+ document.body.style.top = "";
63
+ document.body.style.left = "";
64
+ document.body.style.right = "";
53
65
  };
54
66
  }, [open, closing]);
55
67
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tp3/chat-widget",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "main": "dist/ChatWidget.js",
5
5
  "module": "dist/ChatWidget.mjs",
6
6
  "types": "dist/ChatWidget.d.ts",
@@ -67,18 +67,31 @@ export default function ChatWidget({
67
67
  const typewriterQueue = useRef<string[]>([]);
68
68
  const typewriterTimer = useRef<ReturnType<typeof setInterval> | null>(null);
69
69
 
70
- // Lock scroll on the page behind the chat.
71
- // Using overflow:hidden on <html> is the standard approach used by
72
- // modal/chat libraries it blocks wheel and touch scroll on desktop
73
- // and mobile without interfering with the keyboard or viewport.
70
+ // Lock scroll on the page behind the chat without blocking scroll
71
+ // inside the chat messages area. Uses position:fixed on body — the
72
+ // chat window is also fixed, so it stays visible and its internal
73
+ // overflow-y:auto container scrolls independently.
74
+ const savedScrollY = useRef(0);
75
+
74
76
  useEffect(() => {
75
77
  if (open && !closing) {
76
- document.documentElement.style.overflow = "hidden";
78
+ savedScrollY.current = window.scrollY;
79
+ document.body.style.position = "fixed";
80
+ document.body.style.top = `-${savedScrollY.current}px`;
81
+ document.body.style.left = "0";
82
+ document.body.style.right = "0";
77
83
  } else {
78
- document.documentElement.style.overflow = "";
84
+ document.body.style.position = "";
85
+ document.body.style.top = "";
86
+ document.body.style.left = "";
87
+ document.body.style.right = "";
88
+ window.scrollTo(0, savedScrollY.current);
79
89
  }
80
90
  return () => {
81
- document.documentElement.style.overflow = "";
91
+ document.body.style.position = "";
92
+ document.body.style.top = "";
93
+ document.body.style.left = "";
94
+ document.body.style.right = "";
82
95
  };
83
96
  }, [open, closing]);
84
97