Skip to content

fix: restore focus after execCommand clipboard fallback (#428) - #461

Merged
presidojay1 merged 1 commit into
StellarTickets:mainfrom
Temi-suwa18:fix/428-clipboard-focus
Nov 19, 2026
Merged

presidojay1 merged 1 commit into
StellarTickets:mainfrom
Temi-suwa18:fix/428-clipboard-focus

Conversation

@Temi-suwa18

@Temi-suwa18 Temi-suwa18 commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The execCommand fallback in copyToClipboard moved focus to a temporary off-screen <textarea> and never returned it. When the element was removed in finally, focus fell to <body>, stranding keyboard and screen-reader users who had pressed Enter on the "Copy gate code" button.

Changes

src/lib/clipboard.ts

  • Capture document.activeElement before appending the textarea.
  • Added aria-hidden="true" and tabIndex = -1 on the textarea so it is invisible to assistive technology and unreachable by Tab.
  • Switched from textarea.select() to textarea.focus() + setSelectionRange(0, length) — required for iOS Safari to actually select text in the fallback path.
  • Restored the previously focused element with previousFocus?.focus?.() in finally, after the textarea is removed.

src/lib/clipboard.test.ts

  • Added focus-restoration test: appends a <button>, focuses it, calls copyToClipboard, asserts document.activeElement is the button again afterwards.
  • Added no-focused-element test: verifies the function does not throw when activeElement is <body> (the no-op focus path).

Closes #428
Closes #429
Closes #430
Closes #431

@netlify

netlify Bot commented Nov 19, 2026

Copy link
Copy Markdown

👷 Deploy request for stellartickets pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 596fab5

@drips-wave

drips-wave Bot commented Nov 19, 2026

Copy link
Copy Markdown

@Temi-suwa18 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@presidojay1
presidojay1 merged commit be58374 into StellarTickets:main Nov 19, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants