fix: next input area is now selected via a css query

This commit is contained in:
Johannes Eder 2021-05-27 17:31:16 +02:00
parent 2450e03173
commit 1aaf254c3c

View File

@ -1,7 +1,7 @@
import { Utility } from '../../core/utility';
const ENTER_IS_TAB_INITIALIZED_CLASS = 'enter-as-tab--initialized';
const FORM_GROUP_INPUT_ID = 'hident29';
const AREA_SELECTOR = 'input, textarea';
@Utility({
selector: '[uw-enter-as-tab]',
@ -30,8 +30,19 @@ export class EnterIsTab {
this._element.addEventListener('keypress', (e) => {
if(e.key === 'Enter') {
e.preventDefault();
let messageArea = document.getElementById(FORM_GROUP_INPUT_ID);
messageArea.focus();
let currentInputFieldId = this._element.id;
let inputAreas = document.querySelectorAll(AREA_SELECTOR);
let nextInputArea = null;
for (let i = 0; i < inputAreas.length; i++) {
if(inputAreas[i].id === currentInputFieldId) {
nextInputArea = inputAreas[i+1];
break;
}
}
if(nextInputArea) {
nextInputArea.focus();
}
}
});
}