Skip to content

Commit

Permalink
Put back the focus after modal closes
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreycrofte committed Dec 26, 2022
1 parent 48b029d commit bc2da0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions assets/js/juiz-social-post-sharer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
/**!
* Plugin Name: Nobs • Share Buttons
* Plugin URI: https://sharebuttons.social
* Author: Geoffrey Crofte
* Updated: 2.0.0 - No jQuery needed anymore.
* Updated: 2.3.2 - No jQuery needed anymore.
*/
;
document.addEventListener("DOMContentLoaded", function(event) {
Expand Down Expand Up @@ -305,6 +305,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
return;
}
let animation = 400;
let focusedEl = document.activeElement;
let post_id = event.target.closest('.juiz_sps_links').getAttribute('data-post-id');
let modalContent = '<div class="juiz-sps-modal-inside">' +
'<div class="juiz-sps-modal-header">' +
Expand Down Expand Up @@ -493,6 +494,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
document.querySelector('.juiz-sps-close').addEventListener('click', function() {
modal.setAttribute('aria-hidden', 'true');
modal.classList.remove('jsps-modal-show');
focusedEl.focus();
temp = setInterval(function() {
modal.remove();
}, 400);
Expand All @@ -511,6 +513,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
});

// Accessibility.
// TODO: not enough
document.querySelector('.juiz-sps-close').addEventListener('blur', function() {
this.closest('.juiz-sps-modal').querySelector('form > p:first-child input').focus();
return false;
Expand Down
Loading

0 comments on commit bc2da0e

Please sign in to comment.