Skip to content

fix(Toast): restore focus to prior element on dismiss#2484

Open
Devil1716 wants to merge 1 commit into
dequelabs:developfrom
Devil1716:fix/2345-toast-restore-focus
Open

fix(Toast): restore focus to prior element on dismiss#2484
Devil1716 wants to merge 1 commit into
dequelabs:developfrom
Devil1716:fix/2345-toast-restore-focus

Conversation

@Devil1716

Copy link
Copy Markdown

Summary

  • Capture document.activeElement before Toast steals focus on show.
  • Restore that element on dismiss (before is--hidden / display: none) and on unmount while shown, so keyboard users are not dropped onto <body>.
  • Adds a regression test covering dismiss → focus return.
  • Fixes Bug: Toast does not restore focus when dismissed #2345

Test plan

  • packages/react Toast unit tests pass (should restore focus to the previously focused element on dismiss)
  • Manual: focus a trigger, show a dismissible Toast, Tab to Dismiss, activate — focus returns to the trigger
  • Manual: same flow with Toast portaled / away from the trigger in DOM order

Captures document.activeElement before stealing focus, then restores it on dismiss/unmount so keyboard users are not dropped onto body (fixes dequelabs#2345).

Co-authored-by: Cursor <cursoragent@cursor.com>
@Devil1716
Devil1716 requested a review from a team as a code owner July 18, 2026 07:45
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@aws-amplify-us-east-1

Copy link
Copy Markdown

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-2484.d15792l1n26ww3.amplifyapp.com

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Toast does not restore focus when dismissed

2 participants