From a5fefa4ae9fde8a00ebe5200ee8e1faa9ef1a5f8 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Sat, 24 Nov 2018 15:46:41 +0100 Subject: [PATCH] feat(tasks): focus sub task on creation --- src/app/tasks/task/task.component.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/tasks/task/task.component.ts b/src/app/tasks/task/task.component.ts index 043baa9fa7..2d37941d31 100644 --- a/src/app/tasks/task/task.component.ts +++ b/src/app/tasks/task/task.component.ts @@ -111,7 +111,6 @@ export class TaskComponent implements OnInit, OnDestroy, AfterViewInit { .subscribe((id) => { this.isCurrent = (this.task && id === this.task.id); }); - } ngAfterViewInit() { @@ -126,6 +125,13 @@ export class TaskComponent implements OnInit, OnDestroy, AfterViewInit { this.focusSelfElement(); } }); + + // hacky but relatively performant + if (this.task.parentId && Date.now() - 100 < this.task.created) { + setTimeout(() => { + this.focusTitleForEdit(); + }); + } } ngOnDestroy() { @@ -219,6 +225,10 @@ export class TaskComponent implements OnInit, OnDestroy, AfterViewInit { this._elementRef.nativeElement.focus(); } + focusTitleForEdit() { + this.editOnClickEl.nativeElement.focus(); + } + onTaskAdditionalInfoOpenChanged($event) { this._taskService.update(this.task.id, {notes: $event.newVal}); @@ -234,7 +244,7 @@ export class TaskComponent implements OnInit, OnDestroy, AfterViewInit { const isShiftOrCtrlPressed = (ev.shiftKey === true || ev.ctrlKey === true); if (checkKeyCombo(ev, keys.taskEditTitle) || ev.key === 'Enter') { - this.editOnClickEl.nativeElement.focus(); + this.focusTitleForEdit(); // prevent blur ev.preventDefault(); }