Fix popover when closing modal

Closes issue #1310