Skip to content

Commit

Permalink
impr(tab navigation): improve tab navigation
Browse files Browse the repository at this point in the history
allow tab when quick restart is disabled and when its set to enter
allow pressing enter to trigger buttons even when quick restart is set to enter
  • Loading branch information
Miodec committed Mar 3, 2024
1 parent b9092bf commit e093b51
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions frontend/src/ts/controllers/input-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ function handleTab(event: JQuery.KeyDownEvent, popupVisible: boolean): void {
const modalVisible: boolean =
Misc.isPopupVisible("commandLineWrapper") || popupVisible;

if (Config.quickRestart === "esc" || Config.quickRestart === "enter") {
if (Config.quickRestart === "esc") {
// dont do anything special
if (modalVisible) return;

Expand Down Expand Up @@ -863,9 +863,9 @@ function handleTab(event: JQuery.KeyDownEvent, popupVisible: boolean): void {
return;
}

//
event.preventDefault();
$("#restartTestButton").trigger("focus");
if (document.activeElement?.id !== "wordsInput") {
Focus.set(false);
}
}
}

Expand Down Expand Up @@ -931,7 +931,7 @@ $(document).on("keydown", async (event) => {
if (
allowTyping &&
!wordsFocused &&
!["Enter", ...ModifierKeys].includes(event.key)
!["Enter", "Tab", ...ModifierKeys].includes(event.key)
) {
TestUI.focusWords();
if (Config.showOutOfFocusWarning) {
Expand Down Expand Up @@ -972,6 +972,17 @@ $(document).on("keydown", async (event) => {

//enter
if (event.key === "Enter" && Config.quickRestart === "enter") {
//check if active element is a button, anchor, or has class button, or textButton
const activeElement: HTMLElement | null =
document.activeElement as HTMLElement;
const activeElementIsButton: boolean =
activeElement?.tagName === "BUTTON" ||
activeElement?.tagName === "A" ||
activeElement?.classList.contains("button") ||
activeElement?.classList.contains("textButton");

if (activeElementIsButton) return;

const modalVisible: boolean =
Misc.isPopupVisible("commandLineWrapper") || popupVisible;

Expand Down

0 comments on commit e093b51

Please sign in to comment.