Modal focus

This is based on pull request #1892 from @mlilli. I rebased and squashed it as @pkozlowski-opensource requested. I also made it re-apply focus to the first autofocus element so that it works if you open the modal more than once.