Well, it would probably best be done via script.
But the only way I can tell you is to set the Popup relation to Menu (Closed on any action.) as in my shot below. But this will close it on clicking anywhere, including the popup itself.
Scripting would get a better result. Afraid I can't help there.