Make elements with tabIndex accessible via keyword

This commit is contained in:
Tetrakern 2023-01-23 22:22:49 +01:00
parent 3dd5dba9e3
commit 93f98752c0
2 changed files with 25 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -1278,6 +1278,30 @@ _$$('.contact-form').forEach(element => {
);
});
// =============================================================================
// KEYBOARD INPUT
// =============================================================================
/*
* Make elements with tabIndex 0 accessible with keyboard.
*/
fcn_theBody.querySelectorAll('[tabindex="0"]:not(a, input, button, select)').forEach(element => {
element.addEventListener(
'keydown',
e => {
// Only for actions on focused element
if (e.currentTarget != document.activeElement) return;
// When pressing space or enter
if (e.keyCode == 32 || e.keyCode == 13) {
e.preventDefault();
e.currentTarget.click();
}
}
);
});
// =============================================================================
// KEYWORD INPUTS
// =============================================================================