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

Fixes issue with outside clicks on a secondary popover trigger (v2) #1233

Closed

Conversation

jasonrhodes
Copy link
Member

@jasonrhodes jasonrhodes commented Oct 4, 2018

Summary

Closes #1218 -- only renders the "outside click detector" component when the popover is open, so that the listeners are mounted and unmounted at the correct times and you don't get unexpected listeners firing.

Note: this is "v2" of this PR because the first one solved this same problem in a more complicated way which led to many more snapshot updates, and the PR also included a ton of editor-driven prettier formatting changes that weren't relevant for this repo.

Checklist

  • This was checked in mobile
  • This was checked in IE11
  • This was checked in dark mode
  • Any props added have proper autodocs
  • Documentation examples were added
  • A changelog entry exists and is marked appropriately
  • This was checked for breaking changes and labeled appropriately
  • Jest tests were updated or added to match the most common scenarios
  • This was checked against keyboard-only and screenreader scenarios

@@ -292,41 +292,52 @@ exports[`EuiInMemoryTable behavior pagination 1`] = `
panelPaddingSize="none"
Copy link
Member Author

Choose a reason for hiding this comment

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

This diff looks a lot worse than it is (VS Code was able to actually show the diff much better for some reason). The only change here is that the wrapping outside click detector component is no longer present because the popover uses isOpen={false} here.

@@ -35,7 +35,7 @@ export default class extends Component {
iconSide="right"
onClick={this.onButtonClick.bind(this)}
>
Show popover
Toggle popover
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this to emphasize that this example demonstrates a button that works as a toggle, whereas the secondary click example demonstrates a button that only opens (which I hope will help explain that the secondary trigger cannot be set up to do that, it will always work as a toggle). I could be overthinking whether this is really worth explaining in the docs. :)

@jasonrhodes
Copy link
Member Author

jasonrhodes commented Oct 4, 2018

I was a bit surprised that this change didn't cause any of the popover tests to fail. I think it might be because those tests are using render and mount instead of shallow, so the outside click detector disappears from the output either way? But I didn't want to mess with those tests too much. Let me know if you have thoughts there.

UPDATE: Added 2 tests for presence of outside click detector component. Also unified the "id" prop to be a hard-coded single value so that snapshots don't fail when new tests are added in that popover test file.

@@ -3,7 +3,7 @@
exports[`EuiPopover children is rendered 1`] = `
Copy link
Member Author

Choose a reason for hiding this comment

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

This file was using a getId() function to generate sequential id values for each test. That made a bunch of snapshots "fail" when new tests were added in between others, which didn't seem useful. I talked to @chandlerprall and we agreed hard-coding these ids is better (not sure if the IDs really even need to exist in the test tbh, but left them there as hard-coded values for now).

.toMatchSnapshot();
});

test('outside click detector is not rendered when closed', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

The diff is a little mixed up, but this is 1 of the 2 new tests.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

I'm still seeing a couple of issues.


Can you take a look at the html button example, I'm getting a weird behavior where clicking the trigger button removes it from the dom.

id="popover"
button={button}
isOpen={this.state.isPopoverOpen}
closePopover={this.closePopover}
Copy link
Contributor

Choose a reason for hiding this comment

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

The closePopover doesn't seem to work

Usually you pass a button node to the popover whose onClick handler
will open the popover or toggle the popover open and closed. You can
also trigger this behavior from other elements that live outside of
the popover element. Note: clicks on these outside elements while
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move the note into a warning callout.

@thompsongl
Copy link
Contributor

Is it possible that #1527 (now part of 6.10.0) fixed the problem you were addressing here?
Gist: EuiOutsideClickDetector is now disabled until its target EuiPopover is open (regardless of where the opening action came from).

@snide
Copy link
Contributor

snide commented Apr 18, 2019

@jasonrhodes Mind responding to Greg's comment above? Doing some repo cleanup and closing out old PRs. This one might not need to be around anymore.

@jasonrhodes
Copy link
Member Author

Yeah that looks like it probably solves this. Don't have time to fully test right now but I'll re-open if I discover differently later -- thanks!

@jasonrhodes jasonrhodes deleted the secondary-popover-trigger-v2 branch April 18, 2019 16:28
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.

Popovers close on all outside clicks, including open triggers
4 participants