Properly close dt when clicking on the X

This fixes #9642. I hope.