Skip to content

Commit

Permalink
JI-4507 Fix focus after dialog closes (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
runarkasp authored Jun 13, 2024
1 parent f5d27a5 commit 4418ae9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/h5p.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ H5P.init = function (target) {
instance.triggerXAPI('accessed-reuse');
});
actionBar.on('copyrights', function () {
var dialog = new H5P.Dialog('copyrights', H5P.t('copyrightInformation'), copyrights, $container, $actions.find('.h5p-copyrights')[0]);
var dialog = new H5P.Dialog('copyrights', H5P.t('copyrightInformation'), copyrights, $container);
dialog.open(true);
instance.triggerXAPI('accessed-copyright');
});
Expand Down Expand Up @@ -1040,11 +1040,12 @@ H5P.t = function (key, vars, ns) {
* @param {H5P.jQuery} $element
* Which DOM element the dialog should be inserted after.
* @param {H5P.jQuery} $returnElement
* Which DOM element the focus should be moved to on close
* Which DOM element the focus should be moved to on close
*/
H5P.Dialog = function (name, title, content, $element, $returnElement) {
/** @alias H5P.Dialog# */
var self = this;
this.activeElement = document.activeElement;
var $dialog = H5P.jQuery('<div class="h5p-popup-dialog h5p-' + name + '-dialog" aria-labelledby="' + name + '-dialog-header" aria-modal="true" role="dialog" tabindex="-1">\
<div class="h5p-inner">\
<h2 id="' + name + '-dialog-header">' + title + '</h2>\
Expand Down Expand Up @@ -1109,6 +1110,9 @@ H5P.Dialog = function (name, title, content, $element, $returnElement) {
if ($returnElement) {
$returnElement.focus();
}
else if(self.activeElement) {
self.activeElement.focus();
}
else {
$element.focus();
}
Expand Down

0 comments on commit 4418ae9

Please sign in to comment.