fence focus inside modals

This commit is contained in:
ed 2021-08-24 00:26:54 +02:00
parent 4802f8cf07
commit 7e84f4f015
2 changed files with 18 additions and 1 deletions

View file

@ -1013,6 +1013,8 @@ html.light #rui {
#barpos,
#u2conf label,
#rui label,
#modal-ok,
#modal-ng,
#ops {
-webkit-user-select: none;
-moz-user-select: none;

View file

@ -725,11 +725,15 @@ var modal = (function () {
a.onclick = ok;
(ebi('modali') || a).focus();
document.addEventListener('focus', onfocus);
timer.add(onfocus);
};
r.hide = function () {
o.parentNode.removeChild(o);
timer.rm(onfocus);
document.removeEventListener('focus', onfocus);
document.removeEventListener('keydown', onkey);
o.parentNode.removeChild(o);
r.busy = false;
setTimeout(next, 50);
};
@ -748,6 +752,17 @@ var modal = (function () {
cb_ng(null);
}
function onfocus(e) {
var ctr = ebi('modalc');
if (!ctr || !ctr.contains || !document.activeElement || ctr.contains(document.activeElement))
return;
setTimeout(function () {
ebi('modal-ok').focus();
}, 20);
ev(e);
}
function onkey(e) {
if (e.code == 'Enter') {
var a = ebi('modal-ng');