Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix for focus trapping in modal/dialog components #806

Merged
merged 4 commits into from
Oct 5, 2023
Merged

Conversation

stalgiag
Copy link
Contributor

@stalgiag stalgiag commented Oct 4, 2023

Overview

This PR adds a FocusTrapper component that traps focus in children regardless of whether those children are rendered in a portal. This component side steps browser restrictions on modifying focus during events that would lead to browser interface elements becoming focused. It does this by adding focusable divs before and after the child element. Focus events that would lead to focusing on the barrier divs are used to wrap the focus around to the correct focusable element within the child.

This component is added directly into the BasicModal component that extends the React Bootstrap modal component.

Unit tests are added for FocusTrapper.

Problems addressed

Testing

Since this modifies a common component, the potential for side effects are substantial with this PR. I have done a pass of testing for all of the instances of BasicModal use listed below. In all instances focus wrapped to interactive elements as expected. I'd greatly appreciate any additional testing during review.

  • TestPlanReportStatusDialog
  • 'Are you sure you want to exit?' Test Plan Run
  • Candidate Review Completion Date Edit Dialog
  • UpdateTargetDateModal
  • Advancing Test Plan Dialog
  • UpdateVersionModal
  • "Start Over?" Dialog

closes #805
closes #757
partially addresses #785

@stalgiag stalgiag changed the title Fixes for focus trapping in dialog components Fixes for focus trapping in modal components Oct 4, 2023
@stalgiag stalgiag changed the title Fixes for focus trapping in modal components Fix for focus trapping in modal components Oct 4, 2023
@stalgiag stalgiag changed the title Fix for focus trapping in modal components Fix for focus trapping in modal/dialog components Oct 4, 2023
Copy link
Contributor

@alflennik alflennik left a comment

Choose a reason for hiding this comment

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

Thanks for implementing these fixes, I verified they are working. I tested different access methods like mouse, keyboard, VoiceOver and NVDA. As always, it's great to see some new tests appearing 🙏 Code looks good! I'm glad this fix will apply to all modals going forward.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants