Fix for #9111

I have added a unit test for the outlined bug and updated the modal.js to pass.

Let me know if there is anything else you need to merge this.