You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[EuiPopover] Click outside is not called twice on click out of popover. #6498
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.
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.
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. closePopovermust 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!
👋 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):
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 stateconst[isPopoverOpen,setIsPopoverOpen]=useState(false);constclosePopover=()=>setIsPopoverOpen(false);const[isModalVisible,setIsModalVisible]=useState(false);constshowModal=()=>setIsModalVisible(true);constcloseModal=()=>setIsModalVisible(false);constcloseModalAndPopover=()=>{closeModal();closePopover();};constmodal=isModalVisible ? (<EuiConfirmModaltitle="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(<><EuiPopoverbutton={button}isOpen={isPopoverOpen}closePopover={closePopover}// These new `focusTrapProps` settings are the important things to set herefocusTrapProps={{clickOutsideDisables: false,onClickOutside: showModal,}}>
// ... popover content
</EuiPopover>{modal}</>);
Hope that helps solve your use case - please let us know if not.
Activity
cee-chen commentedon Dec 22, 2022
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.
Kuznietsov commentedon Dec 22, 2022
@cee-chen, I'm creating it.
cee-chen commentedon Dec 22, 2022
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.
Kuznietsov commentedon Dec 22, 2022
@cee-chen, here is a sandbox: https://codesandbox.io/s/eui-popover-modal-focus-bug-7vuqb9.
This bug is not reproducible on v26.0.0.
cee-chen commentedon Dec 22, 2022
Perfection, thank you @Kunzetsov! I think I see the issue. Unfortunately the
closePopovercallback cannot be repurposed to not actually close the popover based on the confirm modal prompt.closePopovermust 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.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!
cee-chen commentedon Dec 22, 2022
👋 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:
Hope that helps solve your use case - please let us know if not.
Kuznietsov commentedon Dec 23, 2022
@cee-chen, thanks a lot for your fast response 🎉