Issue #5558: Fix dialogs not hiding properly

More general fix for issue #5559
@redmunds
cc @peterflynn