ensure original element isn't focused when showing modal

This commit is contained in:
tophf 2021-08-12 16:37:53 +03:00
parent 4817601967
commit 6423ae02b9
2 changed files with 4 additions and 1 deletions

View File

@ -53,6 +53,9 @@ messageBox.show = async ({
if (focusAccessibility.lastFocusedViaClick && document.activeElement) {
document.activeElement.dataset.focusedViaClick = '';
}
if (document.activeElement === messageBox._originalFocus) {
document.body.focus();
}
if (typeof onshow === 'function') {
onshow(messageBox.element);

View File

@ -260,7 +260,7 @@ function moveFocus(rootElement, step) {
const activeIndex = step ? Math.max(step < 0 ? 0 : -1, elements.indexOf(activeEl)) : -1;
const num = elements.length;
if (!step) step = 1;
for (let i = 1; i < num; i++) {
for (let i = 1; i <= num; i++) {
const el = elements[(activeIndex + i * step + num) % num];
if (!el.disabled && el.tabIndex >= 0) {
el.focus();