Skip to content
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

Merged
merged 2 commits into from
Nov 9, 2017

Conversation

aduth
Copy link
Member

@aduth aduth commented Oct 30, 2017

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:

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.

@aduth aduth added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Browser Issues Issues or PRs that are related to browser specific problems labels Oct 30, 2017
@codecov
Copy link

codecov bot commented Oct 30, 2017

Codecov Report

Merging #3235 into master will increase coverage by 0.19%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
components/autocomplete/index.js 77.47% <100%> (+0.67%) ⬆️
...omponents/higher-order/with-focus-outside/index.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c266238...6696861. Read the comment docs.

@ephox-mogran
Copy link
Contributor

This is so similar to our first iteration of #2948. I see you're going with the setTimeout solution, rather than the focusin on the document (like how react-click-outside works). I think focusin for the document may not detect when we try to focus something not in the DOM (or not focusable) and it defaults to body, so it's probably for the best.

@aduth
Copy link
Member Author

aduth commented Oct 30, 2017

This is so similar to our first iteration of #2948.

Yes, h/t could have been more explicit, but #2974 was mentioned in the original comment as inspiration. 👍

@ephox-mogran
Copy link
Contributor

No problem at all. Your solution for that issue was a lot nicer than this approach for that issue would have been.

@aduth
Copy link
Member Author

aduth commented Nov 7, 2017

Rebased with consideration of #2896. @EphoxJames could you give this one a look over given updates to the Autocomplete?

Copy link

@BoardJames BoardJames left a 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.

@aduth
Copy link
Member Author

aduth commented Nov 8, 2017

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)
@aduth aduth merged commit 1cbe5e6 into master Nov 9, 2017
@aduth aduth deleted the fix/autocomplete-close branch November 9, 2017 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Browser Issues Issues or PRs that are related to browser specific problems [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to select a slash commands on mobile
3 participants