Skip to content

Conversation

@mgc1194
Copy link
Contributor

@mgc1194 mgc1194 commented Oct 28, 2025

Summary

Fixed a bug in the AI Teaching Assistant where clicking a button would cause focus to unexpectedly jump to another button. When users were prompted to press the space bar after clicking, the space key would inadvertently trigger the newly-focused button instead of having the intended behaviour.

Root Cause: The <FocusLock> component in AiDiffContainer was actively managing focus even when the container wasn't being interacted with. When the component state changed, FocusLock would re-evaluate focusable elements and automatically redirect focus, causing it to jump from the clicked element to other focusable elements.

Solution: Added disabled={!open} prop to the FocusLock component so it only manages focus when the AI Diff container is actually open and being actively used.

New behavior (Development)

In the first video, you can see:

  • Initial focus remains on <body> after clicking "Run"
  • No unexpected focus jumps occur
  • User interactions behave as expected

Old behavior (Production)

In the first video, you can see:

  • Initial focus is on <body>
  • After clicking the "Run" button, the focus unexpectedly jumps to the "Run" button itself
  • Space bar would trigger the focused button instead of the expected behavior
Screen.Recording.2025-10-28.at.12.47.00.mov

The second video demonstrates that FocusLock still functions correctly when the AiDiffContainer is opened, maintaining focus within the container as intended for accessibility.

Screen.Recording.2025-10-28.at.12.47.58.mov

Links

Testing story

Manual Testing:

  • Tested that clicking buttons no longer causes unexpected focus jumps
  • Verified that FocusLock still functions correctly when the AI Diff container is open
  • Confirmed space bar behavior works as expected after button clicks
  • Tested that focus management works correctly during AI response loading/completion

PR Creation Checklist:

  • Tests provide adequate coverage
  • Privacy impacts have been documented
  • Security impacts have been documented
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Follow-up work items (including potential tech debt) are tracked and linked

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a focus management bug in the AI Teaching Assistant where clicking buttons caused unexpected focus jumps due to FocusLock being active even when the container wasn't open.

  • Disables FocusLock when the AiDiffContainer is closed to prevent unwanted focus management
  • Maintains proper focus containment when the container is actively being used
  • Resolves space bar triggering wrong buttons after focus jumps

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mgc1194 mgc1194 requested review from a team, etaderhold and fisher-alice and removed request for a team October 29, 2025 15:59
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.

1 participant