Skip to content

Commit 4418ae9

Browse files
authoredJun 13, 2024
JI-4507 Fix focus after dialog closes (#179)
1 parent f5d27a5 commit 4418ae9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎js/h5p.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ H5P.init = function (target) {
186186
instance.triggerXAPI('accessed-reuse');
187187
});
188188
actionBar.on('copyrights', function () {
189-
var dialog = new H5P.Dialog('copyrights', H5P.t('copyrightInformation'), copyrights, $container, $actions.find('.h5p-copyrights')[0]);
189+
var dialog = new H5P.Dialog('copyrights', H5P.t('copyrightInformation'), copyrights, $container);
190190
dialog.open(true);
191191
instance.triggerXAPI('accessed-copyright');
192192
});
@@ -1040,11 +1040,12 @@ H5P.t = function (key, vars, ns) {
10401040
* @param {H5P.jQuery} $element
10411041
* Which DOM element the dialog should be inserted after.
10421042
* @param {H5P.jQuery} $returnElement
1043-
* Which DOM element the focus should be moved to on close
1043+
* Which DOM element the focus should be moved to on close
10441044
*/
10451045
H5P.Dialog = function (name, title, content, $element, $returnElement) {
10461046
/** @alias H5P.Dialog# */
10471047
var self = this;
1048+
this.activeElement = document.activeElement;
10481049
var $dialog = H5P.jQuery('<div class="h5p-popup-dialog h5p-' + name + '-dialog" aria-labelledby="' + name + '-dialog-header" aria-modal="true" role="dialog" tabindex="-1">\
10491050
<div class="h5p-inner">\
10501051
<h2 id="' + name + '-dialog-header">' + title + '</h2>\
@@ -1109,6 +1110,9 @@ H5P.Dialog = function (name, title, content, $element, $returnElement) {
11091110
if ($returnElement) {
11101111
$returnElement.focus();
11111112
}
1113+
else if(self.activeElement) {
1114+
self.activeElement.focus();
1115+
}
11121116
else {
11131117
$element.focus();
11141118
}

0 commit comments

Comments
 (0)
Please sign in to comment.