Dialog: Only handle escape events when open

To fix an issue with my code for bug T52868

Bug: T52868
Change-Id: I0047bd9dd535291291f6d864c3d685bc9e725fe3