Fix macro name selection

This commit is contained in:
Farkas József
2016-12-05 20:06:13 +01:00
parent cded85ed9c
commit a6402d7255
@@ -1,5 +1,5 @@
import { import {
AfterViewInit, ChangeDetectionStrategy, Component, ElementRef, Input, Renderer, AfterViewInit, ChangeDetectionStrategy, Component, ElementRef, Input, OnChanges, Renderer,
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
@@ -16,13 +16,19 @@ import { AppState } from '../../../store/index';
styles: [require('./macro-header.component.scss')], styles: [require('./macro-header.component.scss')],
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class MacroHeaderComponent implements AfterViewInit { export class MacroHeaderComponent implements AfterViewInit, OnChanges {
@Input() macro: Macro; @Input() macro: Macro;
@Input() isNew: boolean; @Input() isNew: boolean;
@ViewChild('macroName') macroName: ElementRef; @ViewChild('macroName') macroName: ElementRef;
constructor(private store: Store<AppState>, private renderer: Renderer) { } constructor(private store: Store<AppState>, private renderer: Renderer) { }
ngOnChanges() {
if (this.isNew) {
this.renderer.invokeElementMethod(this.macroName.nativeElement, 'select', []);
}
}
ngAfterViewInit() { ngAfterViewInit() {
if (this.isNew) { if (this.isNew) {
this.renderer.invokeElementMethod(this.macroName.nativeElement, 'select', []); this.renderer.invokeElementMethod(this.macroName.nativeElement, 'select', []);
@@ -45,4 +51,5 @@ export class MacroHeaderComponent implements AfterViewInit {
this.store.dispatch(MacroActions.editMacroName(this.macro.id, name)); this.store.dispatch(MacroActions.editMacroName(this.macro.id, name));
} }
} }