fix: prevent parent scroll on keyboard navigation in preview - #526
fix: prevent parent scroll on keyboard navigation in preview#526waterWang wants to merge 1 commit into
Conversation
When the Image preview is open and the user presses LEFT/RIGHT arrow keys to switch images, the browser's default scroll behavior was not prevented. This caused the parent element to scroll instead of the Image preview navigating between images. The fix adds event.preventDefault() when handling LEFT and RIGHT key events in the Preview component, preventing the browser's default scroll behavior. Closes ant-design/ant-design#56290
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
@waterWang is attempting to deploy a commit to the afc163's projects Team on Vercel. A member of the Team first needs to authorize it. |
Walkthrough预览组的左右方向键处理新增 Changes预览键盘导航
Estimated code review effort: 1 (简单) | ~5 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/Preview/index.tsx (1)
351-354: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win为方向键默认行为增加回归断言。
现有
tests/previewGroup.test.tsx只验证图片切换,没有验证event.defaultPrevented。请为 LEFT 和 RIGHT 事件增加断言,确保后续改动不会移除event.preventDefault()。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Preview/index.tsx` around lines 351 - 354, 在 tests/previewGroup.test.tsx 的方向键事件测试中,为 LEFT 和 RIGHT 两种按键分别增加 event.defaultPrevented 断言,确保触发图片切换时仍调用 event.preventDefault();保留现有图片切换断言不变。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/Preview/index.tsx`:
- Around line 351-354: 在 tests/previewGroup.test.tsx 的方向键事件测试中,为 LEFT 和 RIGHT
两种按键分别增加 event.defaultPrevented 断言,确保触发图片切换时仍调用
event.preventDefault();保留现有图片切换断言不变。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d36a4d48-b6b1-4645-ba05-12ec05679cfd
📒 Files selected for processing (1)
src/Preview/index.tsx
Description
When the Image preview is open and the user presses LEFT/RIGHT arrow keys to switch images, the browser's default scroll behavior was not prevented. This caused the parent element to scroll instead of the Image preview navigating between images.
Root Cause
The
onKeyDownhandler inPreview/index.tsxhandles LEFT/RIGHT arrow keys to navigate between images, but does not callevent.preventDefault(). The browser's default behavior for arrow keys is to scroll the scrollable parent element.Fix
Added
event.preventDefault()when handling LEFT and RIGHT key events in the Preview component, preventing the browser's default scroll behavior.Related Issue
Closes ant-design/ant-design#56290 — Image 键盘切换图片,外部元素会跟着滚动
Summary by CodeRabbit