From 01ca31b4e72c78f3b7e40bbd58161e47f966258b Mon Sep 17 00:00:00 2001
From: ryan-ziqi <877520264@qq.com>
Date: Sat, 8 Mar 2025 23:43:51 +0800
Subject: [PATCH 1/3] fix: panel not follow when scroll is visible
---
src/hooks/useTarget.ts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/hooks/useTarget.ts b/src/hooks/useTarget.ts
index 840cbf3..10d4c11 100644
--- a/src/hooks/useTarget.ts
+++ b/src/hooks/useTarget.ts
@@ -85,8 +85,12 @@ export default function useTarget(
updatePos();
// update when window resize
window.addEventListener('resize', updatePos);
+ // update when `document.body.style.overflow` is set to visible
+ // by default, it will be set to hidden
+ window.addEventListener('scroll', updatePos);
return () => {
window.removeEventListener('resize', updatePos);
+ window.removeEventListener('scroll', updatePos);
};
}, [targetElement, open, updatePos]);
From 19cf2fc7a4d43851d71a6e649f873f8ebd50caf4 Mon Sep 17 00:00:00 2001
From: yellworyan <877520264@qq.com>
Date: Tue, 11 Mar 2025 21:33:52 +0800
Subject: [PATCH 2/3] test: add scroll test case
---
tests/index.test.tsx | 66 +++++++++++++++++++++++++++++++++++++++++++-
tests/utils.ts | 8 +++++-
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/tests/index.test.tsx b/tests/index.test.tsx
index 0dffea0..6f27163 100644
--- a/tests/index.test.tsx
+++ b/tests/index.test.tsx
@@ -7,7 +7,7 @@ import type { TourProps } from '../src/index';
import Tour from '../src/index';
import { getPlacements, placements } from '../src/placements';
import { getPlacement } from '../src/util';
-import { resizeWindow } from './utils';
+import { resizeWindow, scrollWindow } from './utils';
const mockBtnRect = (
rect: {
@@ -1225,4 +1225,68 @@ describe('Tour', () => {
// Check container has children
expect(children).toBeTruthy();
});
+
+ it('should update position when window scroll', async () => {
+ mockBtnRect({
+ x: 80,
+ y: 333,
+ width: 230,
+ height: 180,
+ });
+ const Demo = () => {
+ const btnRef = useRef