Bootstrap modal restores button focus on close
You can use this method, to make the modal-trigger loose focus when you close the modal:
$('#myModal').on('shown.bs.modal', function (e) {
$('#modalTrigger').one('focus', function (e) {
$(this).blur();
});
});
Example:
$(document).ready(function() {
$('#myModal').on('shown.bs.modal', function (e) {
$('#modalTrigger').one('focus', function (e) {
$(this).blur();
});
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
</head>
<body>
<button id="modalTrigger" type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Open modal
</button>
<!-- The Modal -->
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
Blur buttons when modal closes.
$('body').on('hidden.bs.modal', '.modal', function() {
$('.btn').blur();
});