-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check to ensure focus has intentionally left the wrapped component in withFocusOutside
HOC
#17051
Check to ensure focus has intentionally left the wrapped component in withFocusOutside
HOC
#17051
Conversation
… focus Previously there was no check to see whether the blur event occured within the wrapped component. If it occurs within then we do not want to trigger the `handleFocusOutside` callback because (by definition) the focus has not moved outside the wrapped element. This may have been a regression introduced in #16878
packages/components/src/higher-order/with-focus-outside/index.js
Outdated
Show resolved
Hide resolved
Looks like that there's a lot of failing tests. |
Yeh I should look at those tests now. |
Previously we fixed the wrong problem. The actual issue is that previously we were handling document blur events as true “focus outside” events when in fact they should be ignored as if the document is not focused then presumably the user did not intent the blur.
withFocusOutside
HOC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works as intended but it's not fixing all the issues I hoped it would fix :)
It's not fixing #17042 but it's slightly related.
I'll take a look at that other bug as I might have some insight now I understand this area of the code better. Thanks for approving review 👍 |
… `withFocusOutside` HOC (WordPress#17051) * Adds check to determine whether event occured within element trapping focus Previously there was no check to see whether the blur event occured within the wrapped component. If it occurs within then we do not want to trigger the `handleFocusOutside` callback because (by definition) the focus has not moved outside the wrapped element. This may have been a regression introduced in WordPress#16878 * Fix handling blur event when document is not actually focused Previously we fixed the wrong problem. The actual issue is that previously we were handling document blur events as true “focus outside” events when in fact they should be ignored as if the document is not focused then presumably the user did not intent the blur. * Update to test for document loss of focus scenario
… `withFocusOutside` HOC (#17051) * Adds check to determine whether event occured within element trapping focus Previously there was no check to see whether the blur event occured within the wrapped component. If it occurs within then we do not want to trigger the `handleFocusOutside` callback because (by definition) the focus has not moved outside the wrapped element. This may have been a regression introduced in #16878 * Fix handling blur event when document is not actually focused Previously we fixed the wrong problem. The actual issue is that previously we were handling document blur events as true “focus outside” events when in fact they should be ignored as if the document is not focused then presumably the user did not intent the blur. * Update to test for document loss of focus scenario
… `withFocusOutside` HOC (#17051) * Adds check to determine whether event occured within element trapping focus Previously there was no check to see whether the blur event occured within the wrapped component. If it occurs within then we do not want to trigger the `handleFocusOutside` callback because (by definition) the focus has not moved outside the wrapped element. This may have been a regression introduced in #16878 * Fix handling blur event when document is not actually focused Previously we fixed the wrong problem. The actual issue is that previously we were handling document blur events as true “focus outside” events when in fact they should be ignored as if the document is not focused then presumably the user did not intent the blur. * Update to test for document loss of focus scenario
// this blur event thereby leaving focus in place. | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus. | ||
if ( ! document.hasFocus() ) { | ||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line necessary, or is the fix contained in just avoiding the callback?
Notably, the focus
event is not cancellable, so it doesn't seem like this should be doing anything.
See: https://developer.mozilla.org/en-US/docs/Web/API/Element/focus_event
withFocusOutside
HOC aims to detect when a focus occurs outside of the wrapped compomnent.Previously there was no check to see whether the blur event occurred within the wrapped component.
If it occurs within then we do not want to trigger the
handleFocusOutside
callback because (by definition) the focus has not moved outside the wrapped element.This may have been a regression introduced by removal of
react-click-outside
in #16878How has this been tested?
Still working on this.
Types of changes
Bug fix (non-breaking change which fixes an issue
Checklist: