@@ -2969,6 +2978,8 @@
dropdown.style.top = (button_rect.top - context_rect.top) + 'px';
dropdown.style.left = (button_rect.left - context_rect.left + button_rect.width - dropdown_rect.width) + 'px';
+
+ document.getElementById('download-format').focus();
}
});
@@ -2977,10 +2988,44 @@
e.stopPropagation();
});
+// Keyboard handling inside the download dialog: focus trap + Escape to close
+document.getElementById('download-dropdown').addEventListener('keydown', function(e) {
+ const dropdown = document.getElementById('download-dropdown');
+ if (!dropdown.classList.contains('show')) return;
+
+ if (e.key === 'Escape') {
+ e.preventDefault();
+ dropdown.classList.remove('show');
+ document.getElementById('download-div').focus();
+ return;
+ }
+
+ if (e.key === 'Tab') {
+ const focusable = dropdown.querySelectorAll(
+ 'select, input:not([type=hidden]), button, [tabindex]:not([tabindex="-1"])'
+ );
+ const visible = Array.from(focusable).filter(el => el.offsetParent !== null);
+ if (visible.length === 0) return;
+
+ const first = visible[0];
+ const last = visible[visible.length - 1];
+
+ if (e.shiftKey && document.activeElement === first) {
+ e.preventDefault();
+ last.focus();
+ } else if (!e.shiftKey && document.activeElement === last) {
+ e.preventDefault();
+ first.focus();
+ }
+ }
+});
+
// Close dropdown when clicking outside
document.addEventListener('click', function() {
const dropdown = document.getElementById('download-dropdown');
- dropdown.classList.remove('show');
+ if (dropdown.classList.contains('show')) {
+ dropdown.classList.remove('show');
+ }
});
// Handle "Other" format selection
@@ -3051,6 +3096,7 @@
// Close dropdown
document.getElementById('download-dropdown').classList.remove('show');
+ document.getElementById('download-div').focus();
});