Skip to content

Fix: Clear selection after programmatic focus to prevent Firefox text selection (fixes #843)#844

Merged
oliverfoster merged 1 commit intomasterfrom
issue/843
Apr 13, 2026
Merged

Fix: Clear selection after programmatic focus to prevent Firefox text selection (fixes #843)#844
oliverfoster merged 1 commit intomasterfrom
issue/843

Conversation

@swashbuck
Copy link
Copy Markdown
Contributor

@swashbuck swashbuck commented Mar 31, 2026

Fixes #843

Fix

  • In _refocusCurrentActiveElement(), call window.getSelection()?.removeAllRanges() immediately after the programmatic focus() call

Testing

  1. Enable _accessibility._isEnabled: true in config.json
  2. Open a page with body text in Firefox
  3. Click a focusable element (e.g. a nav button) to give it focus
  4. Click on non-focusable body text repeatedly
  5. Verify no text is unexpectedly selected

Test in Chrome to confirm no regression.

JAWS regression check: The _refocusCurrentActiveElement() method being modified was introduced in #697 to prevent JAWS from scrolling when its virtual cursor interacts with grouped elements. removeAllRanges() only affects browser text selection state, which JAWS does not use, so regression is unlikely - but if JAWS testing is available, verify focus behaviour on role=group elements after this change.

Root Cause

PR #697 (v6.72.1) added _refocusCurrentActiveElement() to handle a JAWS virtual cursor scrolling issue. This method calls .focus() programmatically on the previously-active element whenever focus unexpectedly returns to body/html (via _onBlur).

Firefox sets a persistent selection anchor when focus is assigned programmatically. Because _onBlur fires between mousedown and mouseup on every click of non-focusable content, Firefox repositions the selection anchor on each click. The next mousedown then extends the selection from that anchor to the new click point.

Calling removeAllRanges() immediately after focus() clears the anchor before mouseup can use it - so no text is selected and there is no visible flash. JAWS is unaffected as it uses its own virtual cursor, not browser text selection state.


Posted via collaboration with Claude Code

@swashbuck swashbuck requested a review from kirsty-hames April 8, 2026 15:05
@oliverfoster oliverfoster merged commit ab2a817 into master Apr 13, 2026
1 check passed
@oliverfoster oliverfoster deleted the issue/843 branch April 13, 2026 09:13
@github-project-automation github-project-automation Bot moved this from Needs Reviewing to Recently Released in adapt_framework: The TODO Board Apr 13, 2026
github-actions Bot pushed a commit that referenced this pull request Apr 13, 2026
## [6.75.2](v6.75.1...v6.75.2) (2026-04-13)

### Fix

* Clear selection after programmatic focus to prevent Firefox text selection bug (fixes #843) (#844) ([ab2a817](ab2a817)), closes [#843](#843) [#844](#844)
@oliverfoster
Copy link
Copy Markdown
Member

🎉 This PR is included in version 6.75.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Projects

Status: Recently Released

Development

Successfully merging this pull request may close these issues.

Firefox - Content unexpectedly selected when _accessibility is enabled

2 participants