From 78ddcf3bd67bdacbe433539121c48ddbc6837007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 14 Feb 2025 16:06:20 +0800 Subject: [PATCH 1/3] fix: draggable --- src/hooks/useScrollDrag.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hooks/useScrollDrag.ts b/src/hooks/useScrollDrag.ts index e901eada..51b20501 100644 --- a/src/hooks/useScrollDrag.ts +++ b/src/hooks/useScrollDrag.ts @@ -39,6 +39,10 @@ export default function useScrollDrag( }; const onMouseDown = (e: MouseEvent) => { + // 如果目标元素设置了 draggable,则跳过滚动逻辑 + if ((e.target as HTMLElement).draggable) { + return; + } // Skip if nest List has handled this event const event = e as MouseEvent & { _virtualHandled?: boolean; From 12f420d28499365d408a49ae4123df0d1df31958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 14 Feb 2025 16:20:42 +0800 Subject: [PATCH 2/3] test: add test case --- src/hooks/useScrollDrag.ts | 2 +- tests/scroll.test.js | 71 ++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/hooks/useScrollDrag.ts b/src/hooks/useScrollDrag.ts index 51b20501..fb3829f8 100644 --- a/src/hooks/useScrollDrag.ts +++ b/src/hooks/useScrollDrag.ts @@ -39,7 +39,7 @@ export default function useScrollDrag( }; const onMouseDown = (e: MouseEvent) => { - // 如果目标元素设置了 draggable,则跳过滚动逻辑 + // Skip if element set draggable if ((e.target as HTMLElement).draggable) { return; } diff --git a/tests/scroll.test.js b/tests/scroll.test.js index 59e2f6ca..19083a2c 100644 --- a/tests/scroll.test.js +++ b/tests/scroll.test.js @@ -576,22 +576,8 @@ describe('List.Scroll', () => { ); }); - it('mouse down drag', () => { - const onScroll = jest.fn(); - const { container } = render( - - {({ id }) =>
  • {id}
  • } -
    , - ); - - function dragDown(mouseY) { + describe('mouse down drag', () => { + function dragDown(container, mouseY) { fireEvent.mouseDown(container.querySelector('li')); let moveEvent = createEvent.mouseMove(container.querySelector('li')); @@ -605,18 +591,57 @@ describe('List.Scroll', () => { fireEvent.mouseUp(container.querySelector('li')); } - function getScrollTop() { + function getScrollTop(container) { const innerEle = container.querySelector('.rc-virtual-list-holder-inner'); const { transform } = innerEle.style; return Number(transform.match(/\d+/)[0]); } - // Drag down - dragDown(100); - expect(getScrollTop()).toBeGreaterThan(0); + it('can move', () => { + const onScroll = jest.fn(); + const { container } = render( + + {({ id }) =>
  • {id}
  • } +
    , + ); - // Drag up - dragDown(-100); - expect(getScrollTop()).toBe(0); + // Drag down + dragDown(container, 100); + expect(getScrollTop(container)).toBeGreaterThan(0); + + // Drag up + dragDown(container, -100); + expect(getScrollTop(container)).toBe(0); + }); + + it('can not move when item add draggable', () => { + const onScroll = jest.fn(); + const { container } = render( + + {({ id }) =>
  • {id}
  • } +
    , + ); + + // 初始滚动应为 0 + expect(getScrollTop(container)).toEqual(0); + // 模拟拖拽 + dragDown(container, 100); + // 验证拖拽后滚动未改变 + expect(getScrollTop(container)).toEqual(0); + }); }); }); From ecd3b2c5c56c2eff1003f31f6221085f49361450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 14 Feb 2025 16:21:03 +0800 Subject: [PATCH 3/3] chore: translate --- tests/scroll.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/scroll.test.js b/tests/scroll.test.js index 19083a2c..410a59e6 100644 --- a/tests/scroll.test.js +++ b/tests/scroll.test.js @@ -636,11 +636,11 @@ describe('List.Scroll', () => { , ); - // 初始滚动应为 0 + // Initial scroll should be 0 expect(getScrollTop(container)).toEqual(0); - // 模拟拖拽 + // Simulate drag action dragDown(container, 100); - // 验证拖拽后滚动未改变 + // Assert that scroll did not change after drag expect(getScrollTop(container)).toEqual(0); }); });