Skip to content

Commit

Permalink
fix(admin-ui): Fix error with rich text editor (trix)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Apr 24, 2019
1 parent c01a0b4 commit b42ead6
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class RichTextEditorComponent implements ControlValueAccessor, AfterViewI
onChange: (val: any) => void;
onTouch: () => void;
disabled = false;
private initialized = false;

@ViewChild('trixEditor') private trixEditor: ElementRef;

Expand All @@ -49,13 +50,17 @@ export class RichTextEditorComponent implements ControlValueAccessor, AfterViewI
}

onTrixChangeHandler = () => {
this.onChange(this.trix.innerHTML);
this.changeDetector.markForCheck();
if (this.initialized) {
this.onChange(this.trix.innerHTML);
this.changeDetector.markForCheck();
}
};

onTrixFocusHandler = () => {
this.onTouch();
this.changeDetector.markForCheck();
if (this.initialized) {
this.onTouch();
this.changeDetector.markForCheck();
}
};

ngAfterViewInit() {
Expand All @@ -82,7 +87,12 @@ export class RichTextEditorComponent implements ControlValueAccessor, AfterViewI

writeValue(value: any) {
if (this.trix.innerHTML !== value) {
this.trix.editor.loadHTML(value);
if (!this.initialized) {
setTimeout(() => {
this.trix.editor.loadHTML(value);
this.initialized = true;
});
}
}
}
}

0 comments on commit b42ead6

Please sign in to comment.