From af6e5e3a0cfb6e2cf5d18b37036b60ef05f3c593 Mon Sep 17 00:00:00 2001 From: Michael Huynh Date: Wed, 25 Oct 2023 17:06:59 +0800 Subject: [PATCH] fix: focus after marking last subtask done (#2795) --- e2e/src/work-view.e2e.ts | 14 ++++++++++++++ src/app/features/tasks/task/task.component.ts | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/e2e/src/work-view.e2e.ts b/e2e/src/work-view.e2e.ts index 459c82ad822..09a0693fb31 100644 --- a/e2e/src/work-view.e2e.ts +++ b/e2e/src/work-view.e2e.ts @@ -114,4 +114,18 @@ module.exports = { .assert.containsText(TASK + ':nth-child(1)', '1 test task hihi') .end(), + + 'should focus previous subtask when marking last subtask done': (browser: NBrowser) => + browser + .loadAppAndClickAwayWelcomeDialog(WORK_VIEW_URL) + .addTask('task1') + .addTask('task2') + .setValue('task:last-child', 'a') + .keys(['task3', browser.Keys.ENTER]) + .setValue('[listid="SUB"] task:nth-child(1)', 'a') + .keys(['task4', browser.Keys.ENTER]) + .moveToElement('[listid="SUB"] task:nth-child(2)', 10, 30) + .click('.task-done-btn') + .assert.containsText(':focus', 'task3') + .end(), }; diff --git a/src/app/features/tasks/task/task.component.ts b/src/app/features/tasks/task/task.component.ts index 776e1e54786..6b125218251 100644 --- a/src/app/features/tasks/task/task.component.ts +++ b/src/app/features/tasks/task/task.component.ts @@ -448,7 +448,11 @@ export class TaskComponent implements OnInit, OnDestroy, AfterViewInit { } const taskEls = Array.from(document.querySelectorAll('task')); - const currentIndex = taskEls.findIndex((el) => document.activeElement === el); + const activeEl = + document.activeElement?.tagName.toLowerCase() === 'task' + ? document.activeElement + : document.activeElement?.closest('task'); + const currentIndex = taskEls.findIndex((el) => el === activeEl); const prevEl = taskEls[currentIndex - 1] as HTMLElement; if (prevEl) { @@ -470,7 +474,11 @@ export class TaskComponent implements OnInit, OnDestroy, AfterViewInit { } const taskEls = Array.from(document.querySelectorAll('task')); - const currentIndex = taskEls.findIndex((el) => document.activeElement === el); + const activeEl = + document.activeElement?.tagName.toLowerCase() === 'task' + ? document.activeElement + : document.activeElement?.closest('task'); + const currentIndex = taskEls.findIndex((el) => el === activeEl); const nextEl = taskEls[currentIndex + 1] as HTMLElement; if (nextEl) {