-
-
Notifications
You must be signed in to change notification settings - Fork 230
fix(toast): prevent toasts from collapsing when pointer is hovering #2771
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
When dismissing a toast by clicking the close button while the mouse is hovering over the toast group, the toasts would immediately collapse even though the cursor was still within the group. This was caused by focus restoration triggering browser hover state recalculation. This fix adds pointer tracking to only restore focus and collapse toasts when the pointer has actually left the toast group, maintaining the expected hover behavior. Changes: - Add isPointerWithin ref to track mouse position over toast group - Update REGION.BLUR handler to check pointer position before collapsing - Add guards: isPointerOut, isOverlappingAndPointerOut - Add actions: setPointerWithin, clearPointerWithin, clearFocusWithin - Only restore focus when pointer has left the group Fixes chakra-ui/ark#3628
🦋 Changeset detectedLatest commit: 31874d6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 79 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@alii13 is attempting to deploy a commit to the Chakra UI Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for GitHub.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
@segunadebayo can you please take a look and review this PR? |
I took a look, and it works for Chrome. I couldn't get to work in Firefox, though. |
8e0a312
to
f530642
Compare
Thank you @segunadebayo, for reviewing the PR. It was indeed not working for Firefox. Can you please re-review/re-validate the PR?
|
@anubra266 tagging you as well ( if you have sometime please take a look at this PR ). |
Closes chakra-ui/ark#3628
📝 Description
Fixes toast group collapsing unexpectedly when dismissing a toast while the mouse is still hovering over the group. This issue was originally reported in Ark UI (chakra-ui/ark#3628) and traced back to the Zag.js toast machine implementation.
⛳️ Current behavior (updates)
When dismissing a toast by clicking the close button while the mouse is hovering over the toast group:
:hover
pseudo-class is removed from the toast group momentarilymouseleave
/mouseenter
events, causing flickering🚀 New behavior
With this fix:
Implementation changes:
isPointerWithin
ref to track mouse position over toast groupignoringMouseEvents
ref to temporarily block mouse events after toast removalREGION.BLUR
handler to check pointer position before collapsingisPointerOut
,isOverlappingAndPointerOut
setPointerWithin
,clearPointerWithin
,clearFocusWithin
,ignoreMouseEventsTemporarily
💣 Is this a breaking change (Yes/No): No
This is a bug fix that improves the user experience without changing any APIs or breaking existing functionality. The fix is framework-agnostic and applies to all implementations (React, Vue, SolidJS, Svelte).
📝 Additional Information
Testing:
Tested in the Solid examples at
http://localhost:3000/toast-overlap
:Files modified:
packages/machines/toast/src/toast-group.machine.ts
packages/machines/toast/src/toast-group.connect.ts
packages/machines/toast/src/toast.types.ts
Related issue: chakra-ui/ark#3628
Before (Bug) ❌
Screen.Recording.2025-10-13.at.10.45.11.AM.mov
After (Fixed) ✅
Screen.Recording.2025-10-13.at.10.45.50.AM.mov