Skip to content

[EuiPopover] Click outside is not called twice on click out of popover. #6498

Closed

Description

@Kuznietsov

Summary

If click outside and do not close the popover, that action is not called after the next click out.

Screen.Recording.2022-12-22.at.18.17.53.mov

Steps to reproduce:

  • Add handler on click out, which will not close the popover.
  • Open the popover. Click out of it.
  • Click multiple times out of the popover. Handler will be called only once.

Activity

  1. cee-chen commented on Dec 22, 2022

    @cee-chen
    Contributor

    Hey @Kunzetsov! Can you provide a reproduction of this inside either 1. EUI's docs/examples, or 2. within a minimum reproducible CodeSandbox (rather than a screencap of Kibana)?

    This is for us to be able to debug the issue and determine if this is an issue on EUI's end, rather than potentially an issue with consumer implementation (e.g. if your app/plugin has a click listener/interceptor that fires before ours and interferes with the event's propagation somehow). Currently, popovers on EUI's docs are working correctly that I can see, leading me to think that this is an implementation issue.

  2. Kuznietsov commented on Dec 22, 2022

    @Kuznietsov
    Author

    @cee-chen, I'm creating it.

  3. cee-chen commented on Dec 22, 2022

    @cee-chen
    Contributor

    Thank you! After looking at your other issue, I'm walking back my implementation issue guess - this is likely an issue with triggering a modal/flyout/other component with a focus trap from within a popover, i.e. multiple focus traps occurring on the page at once. This may be a bit gnarly to fix, since focus traps are a third party dependency, but definitely is a bug.

  4. Kuznietsov commented on Dec 22, 2022

    @Kuznietsov
    Author
  5. cee-chen commented on Dec 22, 2022

    @cee-chen
    Contributor

    Perfection, thank you @Kunzetsov! I think I see the issue. Unfortunately the closePopover callback cannot be repurposed to not actually close the popover based on the confirm modal prompt. closePopover must close the popover, no matter what - the bug being caused in the first screencap is because the popover thinks its state is already closed, hence why outside clicks are not functioning properly.

    The solution on EUI's end is to support a confirm modal / not closing the popover on outside click without breaking the focus trap. This will involve extending our focusTrapProps. I've been tinkering at this the past 30 minutes or so and I think I have a solution for you that I can open in the next few hours or so. As a heads up though, we won't be doing a release over the holidays, so this enhancement/fix won't reach Kibana until early January at the earliest.

    This bug is not reproducible on v26.0.0.

    Interesting, my guess is because we weren't using focus traps that long ago 😅 FWIW we do expect most consumers using EUI to be within a few majors of our most recent release, and in particular for Kibana we handle upgrades for y'all!

  6. cee-chen commented on Dec 22, 2022

    @cee-chen
    Contributor

    👋 Hey @Kunzetsov, just wanted to give you an update on this - here's an example with working custom outside click behavior that you want (confirm modal):

    https://eui.elastic.co/pr_6500/#/layout/popover#custom-outside-click-behavior

    The PR with this working behavior is not yet released and will not be available in Kibana until January, as I mentioned, but when the next Kibana upgrade PR is merged (can be tracked via the EUI label), at that point you will be able to update your code like so:

    // Please make sure your `closePopover` callback is always closing popover state
    const [isPopoverOpen, setIsPopoverOpen] = useState(false);
    const closePopover = () => setIsPopoverOpen(false);
    
    const [isModalVisible, setIsModalVisible] = useState(false);
    const showModal = () => setIsModalVisible(true);
    const closeModal = () => setIsModalVisible(false);
    
    const closeModalAndPopover = () => {
      closeModal();
      closePopover();
    };
    
    const modal = isModalVisible ? (
      <EuiConfirmModal
        title="You have unsaved work"
        onCancel={closeModal}
        onConfirm={closeModalAndPopover}
        cancelButtonText="No, don't do it"
        confirmButtonText="Yes, do it"
        defaultFocusedButton="cancel"
      >
        <p>Are you sure you to close the popover?</p>
      </EuiConfirmModal>
    ) : null;
    
    return (
      <>
        <EuiPopover
          button={button}
          isOpen={isPopoverOpen}
          closePopover={closePopover}
          // These new `focusTrapProps` settings are the important things to set here
          focusTrapProps={{
            clickOutsideDisables: false,
            onClickOutside: showModal,
          }}
        >
          // ... popover content
        </EuiPopover>
        {modal}
      </>
    );

    Hope that helps solve your use case - please let us know if not.

  7. Kuznietsov commented on Dec 23, 2022

    @Kuznietsov
    Author

    @cee-chen, thanks a lot for your fast response 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions