-
Notifications
You must be signed in to change notification settings - Fork 163
feat: mouse down to scroll #293
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough此次更改引入了一个新的自定义钩子 Changes
Assessment against linked issues
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
src/List.tsxOops! Something went wrong! :( ESLint: 8.57.1 Error: Cannot read config file: /.eslintrc.js
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #293 +/- ##
==========================================
- Coverage 98.49% 98.32% -0.17%
==========================================
Files 18 19 +1
Lines 732 778 +46
Branches 177 187 +10
==========================================
+ Hits 721 765 +44
- Misses 11 13 +2 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
src/hooks/useScrollDrag.ts (1)
68-69
: 考虑为stopScroll()
调用添加测试覆盖第 68-69 行的
stopScroll()
调用未被测试覆盖。建议添加测试用例,覆盖在拖动过程中鼠标移动回组件内部时调用stopScroll()
的场景,以确保此逻辑的可靠性。🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 68-69: src/hooks/useScrollDrag.ts#L68-L69
Added lines #L68 - L69 were not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
src/List.tsx
(2 hunks)src/ScrollBar.tsx
(1 hunks)src/hooks/useScrollDrag.ts
(1 hunks)tests/scroll.test.js
(3 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/hooks/useScrollDrag.ts
[warning] 68-69: src/hooks/useScrollDrag.ts#L68-L69
Added lines #L68 - L69 were not covered by tests
🔇 Additional comments (3)
src/ScrollBar.tsx (1)
4-4
: 成功重构并导入 getPageXY
函数
已从 './hooks/useScrollDrag'
导入 getPageXY
函数,优化了代码复用性和组织结构。
tests/scroll.test.js (1)
559-602
: “mouse down drag”测试用例完善,正确模拟了拖拽事件
新增的测试用例有效地测试了鼠标拖动滚动功能,确保了向下和向上拖动的场景得到正确覆盖。
src/List.tsx (1)
440-443
: 正确集成了 useScrollDrag
钩子,实现了鼠标拖动滚动
在组件中使用了 useScrollDrag
钩子,并正确处理了滚动偏移,实现了鼠标拖动滚动的功能,提升了用户体验。
function smoothScrollOffset(offset: number) { | ||
return Math.floor(offset ** 0.5); | ||
} |
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.
处理 smoothScrollOffset
函数中的负偏移值
当 offset
为负数时,smoothScrollOffset
函数将返回 NaN
,因为在 JavaScript 中,负数的 0.5 次幂结果为 NaN
。这可能导致当 offset
为负数时出现问题。建议在计算前对 offset
取绝对值,并根据原始符号返回结果。
建议修改如下:
function smoothScrollOffset(offset: number) {
- return Math.floor(offset ** 0.5);
+ const result = Math.floor(Math.sqrt(Math.abs(offset)));
+ return offset >= 0 ? result : -result;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
function smoothScrollOffset(offset: number) { | |
return Math.floor(offset ** 0.5); | |
} | |
function smoothScrollOffset(offset: number) { | |
const result = Math.floor(Math.sqrt(Math.abs(offset))); | |
return offset >= 0 ? result : -result; | |
} |
resolve ant-design/ant-design#51888
Summary by CodeRabbit
useScrollDrag
自定义钩子,支持通过鼠标拖动进行滚动。RawList
组件以使用新的拖动滚动功能,提升用户交互体验。List.Scroll
组件的测试覆盖,新增了模拟鼠标拖动事件的测试用例。