Skip to content

fix: Fix Toast hover and focus behavior - #7838

Merged
devongovett merged 7 commits into
mainfrom
hover-issue
Feb 28, 2025
Merged

devongovett merged 7 commits into
mainfrom
hover-issue

Conversation

@devongovett

@devongovett devongovett commented Feb 27, 2025 •

Copy link
Copy Markdown
Member

Closes #7834, fixes #1038

  • Fixes useHover so that it fires onHoverEnd when an element is removed. The browsers do not fire pointerleave in this case, but they do fire pointerover on the new target so we can use this to trigger onHoverEnd. This fixes the case where state gets out of sync, causing the timers not to pause when hovering over the region again after removing a toast.
  • Fixes useFocusWithin to fire onBlurWithin when focus moves outside, even when no onBlur is fired. Browsers do not fire blur when an element is removed. However, when focus moves to another element we'll receive a focus event and we can fire onBlurWithin ourselves.
  • Ensures that toast timers are always paused when the region is either hovered or focused.
  • Updates the focus behavior of toasts to restore focus out of the region when closing a toast with the mouse. Keyboard will still move focus to the next toast. This is so that timers resume and do not appear to be "stuck" due to focus being inside the region (but with no visual focus ring).

@rspbot

rspbot commented Feb 27, 2025

Copy link
Copy Markdown

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, looks good.

I found one odd behaviour, it's pretty funny actually, i'm not sure if it's our use of the view transition, but if you go to https://reactspectrum.blob.core.windows.net/reactspectrum/7c52fbb93e978a61c345aed6055f044805e1313b/docs/react-spectrum/Toast.html#auto-dismiss
and you open a bunch of toasts and wait for them to disappear without moving your mouse off the trigger button, then the trigger button will flash to the default state for each animation

@devongovett

Copy link
Copy Markdown
Member Author

I assume that's view transitions since they happen in a layer on top of the page. Does it happen on main?

@snowystinger

Copy link
Copy Markdown
Member

yeah, happens on main, but doesn't happen in the last release
it also appears to block pointer events? I can't open toasts as fast it feels like?

not a big deal, I'm doing something unusual

snowystinger
snowystinger previously approved these changes Feb 27, 2025
@devongovett

Copy link
Copy Markdown
Member Author

yeah view transitions are not interruptible unfortunately, so you have to wait for the animation to finish before you can click again

reidbarber
reidbarber previously approved these changes Feb 27, 2025

@reidbarber reidbarber left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@reidbarber

Copy link
Copy Markdown
Member

Closes #1038, #4951 ?

@devongovett

Copy link
Copy Markdown
Member Author

looks like both of those are working, though #4951 seems to be working before. maybe a browser change fixed it?

@devongovett
devongovett dismissed stale reviews from reidbarber and snowystinger via 9214886 February 27, 2025 18:55
@rspbot

rspbot commented Feb 27, 2025

Copy link
Copy Markdown

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran chromatic, looks good with the auto opening components, no unexpected changes there

@LFDanLu LFDanLu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, verified hover/focus pause the toast auto dismiss and that the timer resumes when blurring/hovering away. Also verified the difference in behavior between mouse and keyboard when dismissing the Toast and the datepicker/rangepicker blur exception as discussed

@devongovett
devongovett added this pull request to the merge queue Feb 28, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Feb 28, 2025
@devongovett
devongovett added this pull request to the merge queue Feb 28, 2025
Merged via the queue into main with commit f28f1f4 Feb 28, 2025
@devongovett
devongovett deleted the hover-issue branch February 28, 2025 00:59
@levrik

levrik commented Feb 28, 2025 •

Copy link
Copy Markdown

I'm wondering if the changes to hover behavior will also help with #7004? From looking at the code I think it could be able to fix the issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useHover yields false negative after the DOM node gets under the cursor because of a DOM mutation

6 participants