-
Notifications
You must be signed in to change notification settings - Fork 183
fix(useMermaidZoom): fix the scrolling issue #399
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: main
Are you sure you want to change the base?
Conversation
WalkthroughThis PR addresses mobile scrolling issues in the Mermaid component by adding device-specific detection and CSS media queries. Changes include enabling horizontal/vertical scrolling and smooth touch interactions on mobile devices, plus refactoring touch handler logic to conditionally allow scrolling based on device type. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/core/src/components/XMarkdownCore/hooks/useMermaidZoom.ts (1)
72-72: Consider using English for code comments.The inline comment is in Chinese. For better international collaboration, consider translating code comments to English.
- if (e.button !== 0) return; // ⭐️ 只响应鼠标左键 + if (e.button !== 0) return; // Only respond to left mouse button
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/core/src/components/XMarkdownCore/components/Mermaid/style.scss(3 hunks)packages/core/src/components/XMarkdownCore/hooks/useMermaidZoom.ts(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/components/XMarkdownCore/hooks/useMermaidZoom.ts (1)
packages/core/src/components/XMarkdownCore/components/Mermaid/types.d.ts (1)
MermaidExposedMethods(46-54)
🔇 Additional comments (6)
packages/core/src/components/XMarkdownCore/hooks/useMermaidZoom.ts (3)
37-42: Mobile detection approach is acceptable for UI optimization.User agent sniffing is generally fragile but acceptable here for optimizing touch behavior based on device type. The regex pattern covers common mobile platforms adequately.
141-141: LGTM! Early return pattern improves readability.The refactoring to use early returns instead of else blocks follows best practices and makes the code more readable.
Also applies to: 151-151
48-48: Verify the touch handling logic and mobile scrolling behavior.There's a potential logic issue with the touch event handlers:
onTouchStartsetsisDragging.value = trueimmediately (viaonStartat line 51), which means by the timeonTouchMoveexecutes, the conditionisMobile && !isDragging.valueon line 88 will befalse, andpreventDefault()will still be called on line 91. This could prevent scrolling even on mobile devices, contradicting the stated intent.The CSS
touch-actionproperties may compensate for this, but the JavaScript logic appears inconsistent. Consider:
- Adding a movement threshold before setting
isDraggingtotrue- Tracking initial touch position and only enabling drag after significant movement
- Relying entirely on CSS
touch-actionand removing the conditional JavaScript logicAlso applies to: 85-94
packages/core/src/components/XMarkdownCore/components/Mermaid/style.scss (3)
13-17: Mobile scrolling optimization looks good.The media query appropriately enables scrolling on mobile devices by changing
overflowfromhiddentoautoand adding iOS smooth scrolling support. The 768px breakpoint is a standard mobile threshold.
96-101: Touch-action property properly enables native panning on mobile.The
touch-action: pan-x pan-ydeclaration allows native horizontal and vertical panning gestures, which should enable smooth scrolling on mobile devices. Combined withoverflow: auto, this provides the expected mobile scrolling behavior.
113-116: Appropriate touch-action for interactive SVG.Setting
touch-action: manipulationon the SVG disables double-tap-to-zoom while preserving pinch-zoom, which improves touch responsiveness for the interactive diagram. This works well with the custom zoom controls provided by the component.
|
close: #398 |
fix #398
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.