From 7e84f4f0154216100930cddbf75b2248ee493fc4 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 24 Aug 2021 00:26:54 +0200 Subject: [PATCH] fence focus inside modals --- copyparty/web/browser.css | 2 ++ copyparty/web/util.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 8bcdd52f..09f96003 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -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; diff --git a/copyparty/web/util.js b/copyparty/web/util.js index fc6efcfa..817d3577 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -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');