When a modal opens, focus should come to the modal. When a modal closes, focus should return to the element that launched it.
Custom Modal
What you’ll need to do is make sure the modal is focusable, with tabindex=-1
. Ensure the focus returns to the button by directing it with javascript’s (or jQuery’s) focus()
. Also give the modal a role='dialog'
so a screen reader will be alerted to the change in context.
Bootstrap Modal
If you copy paste the Bootstrap Modal from the examples, there is no problem, but a few things (the above things) have been removed from the standard example just to highlight what they do.
This is the custom modal content.