Popup: Added check for onBlur to prevent focus setting focus to be incorrectly disabled when closing a menu in Chrome #4804
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.
Problem:
In Chrome, if we were to press enter in a button in a contextual menu we will incorrectly put focus on the body of the page.
The reason is, because when we close the menu in chrome, we would call the onBlur in the Popup component inside the ContextualMenu, we would incorrectly set our containsFocus to be false, as a result when we run unmount, we won't put focus back to the previous element.
Solution:
We can detect in our event to see if we hit this scenario described above, by looking at the relatedTarget (the element that will gain focus), if it's null, we know that either the type is not supported (not in the case of buttons) or that it doesn't exist, which means we're closing the menu and should not set containFocus to be false.
Validation: