fix(Drawer/Modal/Popover/Slideover): prevent unexpected close on touch when interacting with other overlays#5695
Conversation
commit: |
📝 WalkthroughWalkthroughAdds a new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
Thanks for the fix and sorry for the delay! I simplified it a bit:
Let me know what you think 😊 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/runtime/utils/overlay.ts`:
- Around line 22-30: The connectivity check using document.body.contains(target)
can misreport shadow-DOM nodes as disconnected; update the early-return
condition around e.detail.originalEvent and the local target variable so it uses
Node.isConnected (i.e., check target.isConnected) instead of
document.body.contains(target) to decide whether to e.preventDefault() and
return — locate the block that reads const originalEvent =
e.detail.originalEvent and const target = originalEvent.target as HTMLElement
and replace the contains check with a guard that verifies target exists and
target.isConnected before preventing the overlay close.
🧹 Nitpick comments (1)
src/runtime/utils/overlay.ts (1)
33-35: Track the FIXME for Mac OS scrollbar handling.There’s an explicit FIXME for Mac OS behavior; please track it with an issue or follow-up task so it doesn’t get lost.
🔗 Linked issue
Resolves #5694
❓ Type of change
📚 Description
This PR fixes an issue where the
Modalcomponent closes unexpectedly on touch devices after interacting with other overlay elements (likeToast).Problem
On touch devices, when a user:
The modal closes unexpectedly as if the user tapped outside the modal overlay.
Solution
Added a
pointerDownOutsidehandler that prevents the modal from closing when:This ensures the modal only closes on intentional interactions outside its content.
Testing
Added a "Modal with toast" example in the playground (
/components/modal) to reproduce and test this behavior on touch devices.📝 Checklist