diff --git a/js/dom.js b/js/dom.js index 825d1e78..c956d729 100644 --- a/js/dom.js +++ b/js/dom.js @@ -372,18 +372,23 @@ function focusAccessibility() { * Switches to the next/previous keyboard-focusable element * @param {HTMLElement} rootElement * @param {Number} step - for exmaple 1 or -1 + * @returns {HTMLElement|false|undefined} - + * HTMLElement: focus changed, + * false: focus unchanged, + * undefined: nothing to focus */ function moveFocus(rootElement, step) { const elements = [...rootElement.getElementsByTagName('*')]; const activeIndex = Math.max(0, elements.indexOf(document.activeElement)); const num = elements.length; + const {activeElement} = document; for (let i = 1; i < num; i++) { const elementIndex = (activeIndex + i * step + num) % num; // we don't use positive tabindex so we stop at any valid value const el = elements[elementIndex]; if (!el.disabled && el.tabIndex >= 0) { el.focus(); - return; + return activeElement !== el && el; } } } diff --git a/msgbox/msgbox.js b/msgbox/msgbox.js index 1a236c41..9d04c143 100644 --- a/msgbox/msgbox.js +++ b/msgbox/msgbox.js @@ -34,8 +34,9 @@ function messageBox({ document.body.appendChild(messageBox.element); messageBox.originalFocus = document.activeElement; - moveFocus(messageBox.element, 1); - + // skip external links like feedback + while ((moveFocus(messageBox.element, 1) || {}).target === '_blank') {/*NOP*/} + // suppress focus outline when invoked via click if (focusAccessibility.lastFocusedViaClick && document.activeElement) { document.activeElement.dataset.focusedViaClick = ''; }