likeastore / ngDialog

Modals and popups provider for Angular.js applications
http://likeastore.github.io/ngDialog
3.14k stars 692 forks source link

Remove listeners from the body after a dialog is closed #539

Closed unpollito closed 7 years ago

unpollito commented 7 years ago

I have noticed that, whenever a dialog is created and closed, a body listener is not removed. The problem can be reproduced in this fiddle: https://jsfiddle.net/puefcxvw/1/.

In a nutshell, when we create a dialog with the trapFocus option (which is the default), the activateDialog sets a listener in the HTML body. The deactivateDialog method is supposed to remove this listener, but it is not called when we close the dialog; consequently, the listener stays there forever (or until we reload the page).

I have been unable to produce a unit test which verifies this behavior. I could think of two approaches: either looking into how many keydown listeners there are (but I don't know how to do this without jQuery) or spying on the deactivate method (but I cannot access it from the outside).