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

[EuiFlyout] Remain open when mousedown happens inside the flyout #5810

Merged
merged 6 commits into from
Apr 21, 2022

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Apr 18, 2022

Summary

Fixes a bug where in an EuiFlyout with an overlay mask (default config) would be closed when a click event had mousedown inside the flyout and mouseup outside the flyout (e.g., click, drag, and release where release is outside the flyout).

The cause was EuiOverlayMask firing its onClick handler (in this case to close the flyout) on mouseup. There's a lot going on with this, but the gist is that browsers don't align on what element to designate as target when mousedown and mouseup originations don't match.

To solve the problem, I opted to simplify the component composition inside EuiFlyout and allow EuiFocusTrap to handle outside click detection in all cases, rather than have EuiOverlayMask be responsible. This also allowed for refactoring to also have EuiFocusTrap negate the need for EuiOutsideClickDetector.

Before
https://user-images.githubusercontent.com/2728212/163847290-bcbb3543-2e0e-49a2-8a63-ef5699a6128c.mov

After
https://user-images.githubusercontent.com/2728212/163847313-398c4845-c8c6-41bd-8365-ad282585951f.mov

Checklist

  • Checked in Chrome, Safari, Edge, and Firefox
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress 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

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@cee-chen
Copy link
Member

Going to run CI on this 2 more times to try and catch any flakiness

@cee-chen
Copy link
Member

jenkins test this

// If ownFocus is set, wrap with an overlay and allow the user to click it to close it.
if (ownFocus && !isPushed) {
if (isDefaultConfiguration) {
Copy link
Member

@cee-chen cee-chen Apr 19, 2022

Choose a reason for hiding this comment

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

[super optional comment] This var name doesn't say very much to me at first glance - I find the original condition more descriptive. Since it's really only used in two places I'd honestly lean towards either leaving it unabstracted or trying to find a clearer name, e.g. shouldCloseOnOverlayClick

Comment on lines +343 to +347
const onClickOutside =
(isDefaultConfiguration && outsideClickCloses !== false) ||
outsideClickCloses === true
? onClose
: undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Also super optional feedback, but this is pretty confusing to read - I wonder if a useMemo with early returns would be easier to parse?

Suggested change
const onClickOutside =
(isDefaultConfiguration && outsideClickCloses !== false) ||
outsideClickCloses === true
? onClose
: undefined;
const onClickOutside = useMemo(() => {
if (outsideClickCloses === false) return undefined;
if (outsideClickCloses === true) return onClose;
if (isDefaultConfiguration) return onClose;
return undefined;
}, [outsideClickCloses, isDefaultConfiguration]);

After rereading again I'm not super sure this is a huge improvement so feel free to disregard this lol

@kibanamachine
Copy link

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

@cee-chen
Copy link
Member

2nd CI run passed, running again - jenkins test this

@kibanamachine
Copy link

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

Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

I know you're busy with Emotion stuff so just going to go ahead and approve so we have this fix in for next release!

@kibanamachine
Copy link

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

@thompsongl thompsongl merged commit d4106ef into elastic:main Apr 21, 2022
@kibanamachine
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants