-
Notifications
You must be signed in to change notification settings - Fork 165
fix: after selecting and dragging text, the table still scrolls even after releasing the mouse. #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: after selecting and dragging text, the table still scrolls even after releasing the mouse. #328
Changes from 4 commits
f23c381
2aa59f5
0ce568c
bae7ddc
2a1f1b0
24b7327
1fcd09d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -731,4 +731,70 @@ describe('List.Scroll', () => { | |||||
|
||||||
jest.useRealTimers(); | ||||||
}); | ||||||
|
||||||
it('should not scroll after drop table text', () => { | ||||||
|
||||||
const onScroll = jest.fn(); | ||||||
const { container } = render( | ||||||
<List | ||||||
component="ul" | ||||||
itemKey="id" | ||||||
itemHeight={20} | ||||||
height={100} | ||||||
data={genData(200)} | ||||||
onScroll={onScroll} | ||||||
> | ||||||
{({ id }) => <li draggable>{id}</li>} | ||||||
</List>, | ||||||
); | ||||||
// 选中第99个 fixed-item 的文本内容 | ||||||
const fixedItems = container.querySelectorAll('.fixed-item'); | ||||||
const targetItem = fixedItems[99]; | ||||||
if (targetItem) { | ||||||
const range = document.createRange(); | ||||||
range.selectNodeContents(targetItem); | ||||||
const selection = window.getSelection(); | ||||||
selection.removeAllRanges(); | ||||||
selection.addRange(range); | ||||||
} | ||||||
// 模拟将选中的文本拖拽到列表最底部 | ||||||
const listHolder = container.querySelector('.rc-virtual-list-holder'); | ||||||
if (targetItem && listHolder) { | ||||||
// 创建拖拽事件 | ||||||
const dragStartEvent = new DragEvent('dragstart', { bubbles: true }); | ||||||
targetItem.dispatchEvent(dragStartEvent); | ||||||
|
||||||
// 拖拽到最底部 | ||||||
const rect = listHolder.getBoundingClientRect(); | ||||||
const dragOverEvent = new DragEvent('dragover', { | ||||||
bubbles: true, | ||||||
clientY: rect.bottom + 10, | ||||||
}); | ||||||
listHolder.dispatchEvent(dragOverEvent); | ||||||
|
||||||
// 松开鼠标 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The comment contains Chinese text. Consider using English for consistency: '// Release mouse'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
const dropEvent = new DragEvent('drop', { | ||||||
bubbles: true, | ||||||
clientY: rect.bottom + 10, | ||||||
}); | ||||||
listHolder.dispatchEvent(dropEvent); | ||||||
|
||||||
const dragEndEvent = new DragEvent('dragend', { bubbles: true }); | ||||||
targetItem.dispatchEvent(dragEndEvent); | ||||||
} | ||||||
// 检查 onScroll 没有被触发 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The comment contains Chinese text. Consider using English for consistency: '// Check that onScroll was not triggered'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
expect(onScroll).not.toHaveBeenCalled(); | ||||||
|
||||||
// 模拟将鼠标移动到列表最顶部 | ||||||
if (listHolder) { | ||||||
const rect = listHolder.getBoundingClientRect(); | ||||||
const mouseMoveEvent = new MouseEvent('mousemove', { | ||||||
bubbles: true, | ||||||
clientY: rect.top - 10, | ||||||
}); | ||||||
listHolder.dispatchEvent(mouseMoveEvent); | ||||||
} | ||||||
// 检查 onScroll 没有被触发 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The comment contains Chinese text. Consider using English for consistency: '// Check that onScroll was not triggered'.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
expect(onScroll).not.toHaveBeenCalled(); | ||||||
}); | ||||||
QdabuliuQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment contains Chinese text. Consider using English for consistency: '// Unified function to clear drag state'.
Copilot uses AI. Check for mistakes.