Fix for focus trapping in modal/dialog components #806
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.closes #805
closes #757
partially addresses #785