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

[EuiPopover] Fix popover returning focus to correct element #4071

Merged
merged 13 commits into from
Nov 4, 2020

Conversation

chandlerprall
Copy link
Contributor

@chandlerprall chandlerprall commented Sep 23, 2020

Summary

Fixes #4003 and fixes #4107

I've removed a lot of logic from EuiPopover, as it has been duplicated by the stack of focus lock libraries used by the popovers.

popover_return_focus

This has apparently introduced visual issue (or at least exasperated an existing one) where clicking on a popover anchor button often causes that button to move a lot.

popover_jitter

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile

  • Checked in Chrome, Safari, Edge, and Firefox
    - [ ] Props have proper autodocs
    - [ ] Added documentation
  • Checked Code Sandbox works for the any docs examples
    - [ ] Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

Show popover
</EuiButton>
);
const [openPopover, setOpenPopover] = useState(null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is temporary, for testing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to revert this before merging. 😜

@snide
Copy link
Contributor

snide commented Sep 23, 2020

Seems like a good time to just remove the animation. We've been fighting it for awhile. If we can't get around it, I think we should be ok removing that as a blocker. My guess is we'll still have an issue, now with shadows "bouncing" in the animation, so I'd still look into the root.

@cchaos
Copy link
Contributor

cchaos commented Sep 24, 2020

Seems like a good time to just remove the animation.

I disagree that this is a good time/good reason. We rely on this animation in other buttons especially EuiButtonIcon for hover states. I don't want to block the fix for popovers while we investigate all the uses of translate hover state. We do have a specific discuss issue in #2184 for this and should probably be visited via Amsterdam.

I can look into the cause for the double-animation but it might be ok to ship with this tiny regression for now.

@chandlerprall
Copy link
Contributor Author

chandlerprall commented Sep 24, 2020

I can look into the cause for the double-animation but it might be ok to ship with this tiny regression for now.

I'll move forward with this PR on Monday (with the importance on the focus bug, would like to include it in the next release) - if someone can take a look into the animation before then that'd be great, otherwise we can try to re-prioritize #2184

[working through the lint issues, some tests, and other issues now]

@cchaos
Copy link
Contributor

cchaos commented Sep 24, 2020

The focus behavior (aside from the animation) on this one has gotten really funky. Just play around with the "Anchor position" example which "toggles" the popover and you'll see 3 major things.

  1. Every third click doesn't close the popover
  2. When in that ^ state, clicking outside no longer closes it
  3. When clicking outside does work. It should still return focus to original trigger IF what they click on is not interactable. Otherwise the next tabbed item seems arbitrary.

Happy to zoom about or record these for clarification.

I think it's best to finalize the interaction and focus behaviors (JS) before trying to look at the anim bug because they could be related.

@chandlerprall chandlerprall force-pushed the bug/4003-popover-re-focus branch from 6a44e12 to 87eb56a Compare September 24, 2020 17:59
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4071/

@chandlerprall
Copy link
Contributor Author

I am aware of and working on one last issue that this change has created.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4071/

@chandlerprall chandlerprall marked this pull request as ready for review September 29, 2020 18:32
@chandlerprall
Copy link
Contributor Author

@thompsongl @cchaos this is ready for a full review - no rush!

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4071/

@cchaos
Copy link
Contributor

cchaos commented Sep 30, 2020

We still have a bit of a jumpy screen when closing the popover. Here's a video: https://share.getcloudapp.com/DOu9Nvq1

What's happening is I open a popover and then scroll so that it is out of view, when I then click anywhere on the page, it scrolls back up to the original popover's trigger. BUT, if I then tab, the next focusable element is after where I had clicked to dismiss the popover (basically then shooting back down the page).

So essentially if a popover is still open but not visible in the viewport, clicking anywhere will force the window to put that old trigger button back into view even though it's not the currently focused element.

@chandlerprall
Copy link
Contributor Author

@cchaos pushed a fix for jumping back to the anchor when it is re-focused. The fix - which relies on passing a preventScroll configuration to .focus() - reportedly does not work in Safari. However, there is an existing bug in our popovers+FF and Safari where the anchor does not receive focus when pressing esc, which masks this discrepancy.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4071/

@thompsongl
Copy link
Contributor

This appears to be an improvement overall 🎉
A couple things I noticed during manual testing:

  1. EuiFlyout, after clicking the overlay mask to close. Focus is not returned to the button.
    (Not actually sure that I'd expect focus to return to the button in this case, but it's different from the current behavior.)

  2. EuiColorPicker, navigating with keyboard. Focus does not move to the picker handle.
    (Could be the timeout needs to be updated. Setting this focus is somewhat manual.)

@chandlerprall chandlerprall force-pushed the bug/4003-popover-re-focus branch from 57abce2 to 6d6e1be Compare October 29, 2020 16:07
@chandlerprall
Copy link
Contributor Author

chandlerprall commented Oct 29, 2020

Force pushed after rebasing on master, only new commit since last comment is Address unintentional changes to flyouts & color picker 6d6e1be

EuiFlyout, after clicking the overlay mask to close. Focus is not returned to the button.
(Not actually sure that I'd expect focus to return to the button in this case, but it's different from the current behavior.)

I changed EuiFlyout's clickOutsideDisables on EuiFocusTrap to false, which corrects this. It does change the existing behaviour where opening a flyout without ownFocus would reset focus to the button when clicking out of the flyout, instead of selecting the button again when the flyout closes. This is a change in behaviour but feels much better to me.

EuiColorPicker, navigating with keyboard. Focus does not move to the picker handle.
(Could be the timeout needs to be updated. Setting this focus is somewhat manual.)

Greg contributed the fix for this, making color picker explicitly decide where focus should go when the picker pops up.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4071/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good; very happy to see focus_trap simplified 🎉
Manually tested a bunch of docs examples and didn't see any regressions aside from the noted button double-animation.

Don't forget a changelog entry

@elizabetdev elizabetdev mentioned this pull request Nov 4, 2020
5 tasks
Show popover
</EuiButton>
);
const [openPopover, setOpenPopover] = useState(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to revert this before merging. 😜

src/components/flyout/__snapshots__/flyout.test.tsx.snap Outdated Show resolved Hide resolved
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4071/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4071/

@chandlerprall chandlerprall merged commit d3284d5 into elastic:master Nov 4, 2020
@chandlerprall chandlerprall deleted the bug/4003-popover-re-focus branch November 4, 2020 19:02
cchaos pushed a commit to andreadelrio/eui that referenced this pull request Nov 4, 2020
…4071)

* Move onclickoutside / onescape handling to focus-lock lib itself

* Get popover focus return functioning

* Fix lint issues & snapshots, re-enable clickOutsideDisables prop for EuiFocusTrap

* fix popover re-toggling when clicking its anchor

* Re-enable popover outside click and escape key detection when ownFocus is false

* Only call popover's closePopover callback when it is open

* Don't scroll back to a popover anchor when the popover closes

* Address unintentional changes to flyouts & color picker

* changelog

* revert changes to popover example, which had been made to augment testing

* Fix flyout's snapshot tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants