Skip to content

Commit a4c120d

Browse files
committed
feature: accelerator key for accumulator/submit
1 parent 9d0f973 commit a4c120d

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

html/classhelper.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ class ClassHelper extends HTMLElement {
645645
info.textContent = `${startNumber} - ${endNumber}`;
646646

647647
const prev = document.createElement("button");
648-
prev.innerHTML = ">";
648+
prev.innerHTML = "<";
649649
prev.setAttribute("aria-label", ClassHelper.translations["Prev"]);
650650
prev.setAttribute("disabled", "disabled");
651651
if (prevUrl) {
@@ -705,6 +705,7 @@ class ClassHelper extends HTMLElement {
705705
});
706706

707707
const apply = document.createElement("button");
708+
apply.id = "popup-apply";
708709
apply.setAttribute("class", "acc-apply");
709710
apply.textContent = ClassHelper.translations["Apply"];
710711
apply.addEventListener("click", () => {
@@ -925,24 +926,36 @@ class ClassHelper extends HTMLElement {
925926
});
926927

927928
this.popupRef.addEventListener("keydown", (e) => {
928-
if (e.target.tagName == "TR") {
929-
if (e.key === "ArrowDown" && e.target === this.popupRef.document.activeElement) {
929+
if (e.key === "ArrowDown") {
930+
if (e.target.tagName === "TR") {
930931
e.preventDefault();
931932
if (e.target.nextElementSibling != null) {
932933
e.target.nextElementSibling.focus();
933934
} else {
934935
e.target.parentElement.firstChild.focus();
935936
}
937+
} else if (e.target.tagName != "INPUT" && e.target.tagName != "SELECT") {
938+
e.preventDefault();
939+
this.popupRef.document.querySelector("tr.rowstyle").parentElement.firstChild.focus();
936940
}
937-
if (e.key === "ArrowUp" && e.target === this.popupRef.document.activeElement) {
941+
} else if (e.key === "ArrowUp") {
942+
if (e.target.tagName === "TR") {
938943
e.preventDefault();
939944
if (e.target.previousElementSibling != null) {
940945
e.target.previousElementSibling.focus();
941946
} else {
942947
e.target.parentElement.lastChild.focus();
943948
}
949+
} else if (e.target.tagName != "INPUT" && e.target.tagName != "SELECT") {
950+
e.preventDefault();
951+
this.popupRef.document.querySelector("tr.rowstyle").parentElement.lastChild.focus();
944952
}
945-
if (e.key === "Enter" || e.key === " ") {
953+
} else if (e.key === ">") {
954+
this.popupRef.document.getElementById("popup-pagination").lastChild.focus();
955+
} else if (e.key === "<") {
956+
this.popupRef.document.getElementById("popup-pagination").firstChild.focus();
957+
} else if (e.key === "Enter") {
958+
if (e.target.tagName == "TR" && e.shiftKey == false) {
946959
e.preventDefault();
947960
let tr = e.target;
948961
tr.children.item(0).checked = !tr.children.item(0).checked;
@@ -951,30 +964,23 @@ class ClassHelper extends HTMLElement {
951964
value: tr.dataset.id
952965
}
953966
}));
954-
}
955-
if (e.key === ">") {
956-
this.popupRef.document.getElementById("popup-pagination").lastChild.focus();
957-
}
958-
if (e.key === "<") {
959-
this.popupRef.document.getElementById("popup-pagination").firstChild.focus();
960-
}
961-
return;
962-
}
963-
964-
if (e.target.tagName != "INPUT" && e.target.tagName != "SELECT") {
965-
if (e.key === "ArrowDown") {
967+
} else if (e.shiftKey) {
966968
e.preventDefault();
967-
this.popupRef.document.querySelector("tr.rowstyle").parentElement.firstChild.focus();
969+
const applyBtn = this.popupRef.document.getElementById("popup-apply");
970+
if (applyBtn) {
971+
applyBtn.focus();
972+
}
968973
}
969-
if (e.key === "ArrowUp") {
974+
} else if (e.key === " ") {
975+
if (e.target.tagName == "TR" && e.shiftKey == false) {
970976
e.preventDefault();
971-
this.popupRef.document.querySelector("tr.rowstyle").parentElement.lastChild.focus();
972-
}
973-
if (e.key === ">") {
974-
this.popupRef.document.getElementById("popup-pagination").lastChild.focus();
975-
}
976-
if (e.key === "<") {
977-
this.popupRef.document.getElementById("popup-pagination").firstChild.focus();
977+
let tr = e.target;
978+
tr.children.item(0).checked = !tr.children.item(0).checked;
979+
this.dispatchEvent(new CustomEvent("selection", {
980+
detail: {
981+
value: tr.dataset.id
982+
}
983+
}));
978984
}
979985
}
980986
});

0 commit comments

Comments
 (0)