-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Autocomplete: Implement and use focus outside utility for managing dismissal #3235
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3235 +/- ##
=========================================
+ Coverage 31.91% 32.1% +0.19%
=========================================
Files 247 248 +1
Lines 6856 6874 +18
Branches 1246 1248 +2
=========================================
+ Hits 2188 2207 +19
+ Misses 3925 3924 -1
Partials 743 743
Continue to review full report at Codecov.
|
This is so similar to our first iteration of #2948. I see you're going with the |
No problem at all. Your solution for that issue was a lot nicer than this approach for that issue would have been. |
1748685
to
d652ed8
Compare
Rebased with consideration of #2896. @EphoxJames could you give this one a look over given updates to the Autocomplete? |
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.
Clicking in a different part of the paragraph block does not close the popup. I suggest keeping the onClose handler for Popover though you could also just detect any clicks that aren't on the popover.
Good call @EphoxJames , ideally we'd not need both the click-outside detection of the popover and the focus-outside detection of the autocomplete component, but since the popover never truly receives focus it would appear we unfortunately do need to handle both. |
As implemented, Popover portaled content will still fire focus onto root Autocomplete node, so blur trigger will cancel. See: https://reactjs.org/docs/portals.html#event-bubbling-through-portals Components: Restore Autocomplete Popover close behavior Handle click outside which remains in focus of wrapped Autocomplete element (e.g. clicking elsewhere within the same contenteditable should still dismiss Popover)
eadc41c
to
6696861
Compare
Fixes #2669
Related: #3174, #2974
This pull request seeks to improve the behavior of Autocomplete close, resolving an issue where block selection on touch devices does not work correctly. Specifically this resolves an issue iOS devices in the current implementation to test where focus has shifted,
relatedTarget
is the popover contents itself (.components-popover__content
).These changes include a new
withFocusOutside
higher-order component similar to the one suggested in #2974 to help encapsulate logic of testing whether a blur really causes focus to leave an element. This is meant to help in two ways:relatedTarget
is not reliable in IE11 (CodePen, React's blur may not have relatedTarget in IE 9-11 where it is supported. facebook/react#3751, onFocusIn/onFocusOut events facebook/react#6410)relatedTarget
withElement#contains
is not always reliable. As implemented here and leveraging portal event bubbling behavior,withFocusOutside
will account for focus shifting into portaled content.Testing instructions:
Repeat testing instructions from #3174, also confirming selection on a touch device (e.g. XCode iOS simulator).
Verify that there are no regressions in clicking or tabbing outside of the paragraph field while an autocomplete suggestions list is open.