Fix FocusTrap escape due to strange tabindex values #2093
Merged
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.
This PR will now ensure that we can't escape the FocusTrap if you use
<tab>
and you happen to tab to an element outside of the FocusTrap because the next item in line happens to be outside of the FocusTrap and we never hit any of the focus guard elements.How it works is as follows:
onBlur
is implemented on theFocusTrap
itself, this will give us some information in the event itself.e.target
is the element that is being blurred (think of it asfrom
)e.currentTarget
is the element with the event listener (the dialog)e.relatedTarget
is the element we are going to (think of it asto
)<tab>
or<shift>+<tab>
, then we will move focus back inside the FocusTrap, and go from thee.target
to the next or previous value.e.target
value.Fixes: #1656