[Modal] Added "autofocus" option to focus on the first input when shown

Forms are commonly placed within modals, so it's convenient to automatically focus on the first input within them. Thus, I have added a new "autofocus" option. I decided to turn this feature on by default because the modal already saves the currently focused element before being shown and restores it when the modal is hidden, making this a non-breaking change for existing implementations.

Additionally, I altered the order of the onVisible/onHidden calls so that they are called after saving and before restoring the currently focused element. This further break-proofs existing implementations since the user's callbacks are less likely to interfere with the process.

I also made the code a bit more DRY as we were copy/pasting callback functions for animations.