Properly close dt when clicking on the X

This fixes #9642. I hope.

(cherry picked from commit 9b924ffc8fe728d52ddbe4fd5619a40b20636c16)