diff --git a/src/hooks/useScrollDrag.ts b/src/hooks/useScrollDrag.ts index e901eada..fb3829f8 100644 --- a/src/hooks/useScrollDrag.ts +++ b/src/hooks/useScrollDrag.ts @@ -39,6 +39,10 @@ export default function useScrollDrag( }; const onMouseDown = (e: MouseEvent) => { + // Skip if element set draggable + if ((e.target as HTMLElement).draggable) { + return; + } // Skip if nest List has handled this event const event = e as MouseEvent & { _virtualHandled?: boolean; diff --git a/tests/scroll.test.js b/tests/scroll.test.js index 59e2f6ca..410a59e6 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}
  • } +
    , + ); + + // 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); + }); }); });