Skip to content

Commit

Permalink
fix: focus after marking last subtask done (#2795)
Browse files Browse the repository at this point in the history
  • Loading branch information
miqh authored and johannesjo committed Nov 16, 2023
1 parent 62633db commit af6e5e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 14 additions & 0 deletions e2e/src/work-view.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
12 changes: 10 additions & 2 deletions src/app/features/tasks/task/task.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit af6e5e3

Please sign in to comment.