Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
alii13 wants to merge 4 commits into chakra-ui:main
base: main
Choose a base branch
Loading
from alii13:fix/toast-hover-collapse-on-dismiss

Conversation

Copy link

@alii13 alii13 commented Oct 12, 2025
edited
Loading

Closes chakra-ui/ark#3628

📝 Description

Fixes toast group collapsing unexpectedly when dismissing a toast while the mouse is still hovering over the group in the SolidJS implementation. This issue was originally reported in Ark UI (chakra-ui/ark#3628) where it only affected SolidJS, while React and Vue implementations worked correctly. The issue was traced back to the Zag.js toast machine implementation.

⛳️ Current behavior (updates)

SolidJS only: When dismissing a toast by clicking the close button while the mouse is hovering over the toast group:

  • The toasts immediately collapse even though the cursor is still within the group
  • Focus is restored to the trigger button, which causes the browser to recalculate hover state
  • The :hover pseudo-class is removed from the toast group momentarily
  • This results in toasts collapsing unexpectedly, breaking the expected hover behavior
  • The user must move their cursor slightly to re-trigger the hover expansion

React and Vue implementations did not have this issue.

🚀 New behavior

With this fix:

  • Toasts remain expanded when dismissing a toast while hovering over the group
  • Focus restoration only occurs when the pointer has actually left the toast group
  • The hover state is preserved during toast dismissal operations
  • Focus is restored later when the user moves their cursor away from the group
  • SolidJS behavior now matches React and Vue implementations

Implementation 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

💣 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

Affected framework: SolidJS (React and Vue were not affected)

Testing:
Tested in the Solid examples at http://localhost:3000/toast-overlap:

  1. ✅ Create multiple toasts
  2. ✅ Hover over toast group (toasts expand)
  3. ✅ Click X button while hovering (toasts remain expanded - fixed!)
  4. ✅ Move cursor away (toasts collapse and focus returns)

Files modified:

  • packages/machines/toast/src/toast-group.machine.ts
  • packages/machines/toast/src/toast.types.ts

Related issue: chakra-ui/ark#3628 (SolidJS-specific bug)

Before (Bug) ❌

  • Toast group collapses immediately
  • Focus restoration breaks hover state
Screen.Recording.2025年10月13日.at.10.45.11.AM.mov

After (Fixed) ✅

  • Toast group stays expanded
  • Hover state preserved
Screen.Recording.2025年10月13日.at.10.45.50.AM.mov

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 
Copy link

changeset-bot bot commented Oct 12, 2025
edited
Loading

🦋 Changeset detected

Latest commit: 8e0a312

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 79 packages
Name Type
@zag-js/toast Patch
@zag-js/anatomy-icons Patch
@zag-js/anatomy Patch
@zag-js/core Patch
@zag-js/docs Patch
@zag-js/preact Patch
@zag-js/react Patch
@zag-js/solid Patch
@zag-js/svelte Patch
@zag-js/vue Patch
@zag-js/accordion Patch
@zag-js/angle-slider Patch
@zag-js/async-list Patch
@zag-js/avatar Patch
@zag-js/bottom-sheet Patch
@zag-js/carousel Patch
@zag-js/checkbox Patch
@zag-js/clipboard Patch
@zag-js/collapsible Patch
@zag-js/color-picker Patch
@zag-js/combobox Patch
@zag-js/date-picker Patch
@zag-js/dialog Patch
@zag-js/editable Patch
@zag-js/file-upload Patch
@zag-js/floating-panel Patch
@zag-js/hover-card Patch
@zag-js/listbox Patch
@zag-js/menu Patch
@zag-js/navigation-menu Patch
@zag-js/number-input Patch
@zag-js/pagination Patch
@zag-js/password-input Patch
@zag-js/pin-input Patch
@zag-js/popover Patch
@zag-js/presence Patch
@zag-js/progress Patch
@zag-js/qr-code Patch
@zag-js/radio-group Patch
@zag-js/rating-group Patch
@zag-js/scroll-area Patch
@zag-js/select Patch
@zag-js/signature-pad Patch
@zag-js/slider Patch
@zag-js/splitter Patch
@zag-js/steps Patch
@zag-js/switch Patch
@zag-js/tabs Patch
@zag-js/tags-input Patch
@zag-js/timer Patch
@zag-js/toggle-group Patch
@zag-js/toggle Patch
@zag-js/tooltip Patch
@zag-js/tour Patch
@zag-js/tree-view Patch
@zag-js/store Patch
@zag-js/types Patch
@zag-js/aria-hidden Patch
@zag-js/auto-resize Patch
@zag-js/collection Patch
@zag-js/color-utils Patch
@zag-js/utils Patch
@zag-js/date-utils Patch
@zag-js/dismissable Patch
@zag-js/dom-query Patch
@zag-js/file-utils Patch
@zag-js/focus-trap Patch
@zag-js/focus-visible Patch
@zag-js/highlight-word Patch
@zag-js/hotkeys Patch
@zag-js/i18n-utils Patch
@zag-js/interact-outside Patch
@zag-js/json-tree-utils Patch
@zag-js/live-region Patch
@zag-js/popper Patch
@zag-js/rect-utils Patch
@zag-js/remove-scroll Patch
@zag-js/scroll-snap Patch
@zag-js/stringify-state Patch

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

Copy link

vercel bot commented Oct 12, 2025

@alii13 is attempting to deploy a commit to the Chakra UI Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Oct 12, 2025
edited
Loading

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
zag-nextjs Ready Ready Preview Oct 17, 2025 8:23pm
zag-solid Ready Ready Preview Oct 17, 2025 8:23pm
zag-svelte Ready Ready Preview Oct 17, 2025 8:23pm
zag-vue Ready Ready Preview Oct 17, 2025 8:23pm

💡 Enable Vercel Agent with 100ドル free credit for automated AI reviews

Copy link
Author

alii13 commented Oct 13, 2025

@segunadebayo can you please take a look and review this PR?

Copy link
Member

I took a look, and it works for Chrome. I couldn't get to work in Firefox, though.

Use double requestAnimationFrame for blur handling to ensure hover state
is properly settled before processing blur events. This fixes the issue
where Firefox would still collapse toasts when hovering due to different
timing in hover state recalculation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Toast group collapses unexpectedly in SolidJS when closing a toast

AltStyle によって変換されたページ (->オリジナル) /