Ckeditor5-angular: How to set focus on the CKEditor 5 editor?

Created on 17 May 2019  路  4Comments  路  Source: ckeditor/ckeditor5-angular

Hello,

Does anyone know how to set focus in CKEditor 5 component's editor?
My <ckeditor> component is disabled by default, and I would like to set the focus when the user presses a button.

I tried something like this, but the elementRef is private :

addFocus(): void {
  this.isEditing = true;
  this.ckEditor.elementRef.nativeElement.focus();
}
solved question

Most helpful comment

Hello @ma2ciek ,

Thank you a lot for your help :). Just in case someone has the same problem, I followed the ma2ciek help but without 'document' (else I got the error "the function focus is not defined") so :

editorInstance.editing.view.focus();

All 4 comments

Hi @M-Blobby,

the <ckeditor> component exposes the editorInstance, which is an instance of CKEditor 5 editor, on which you can use the editorInstance.editing.view.focus() method to focus the editable element.

Hello @ma2ciek ,

Thank you a lot for your help :). Just in case someone has the same problem, I followed the ma2ciek help but without 'document' (else I got the error "the function focus is not defined") so :

editorInstance.editing.view.focus();

Where does this "editorInstance" come from?
I'm trying to use the ViewChild, to a local reference on but without success :(

Hi @tarcisiocipriano,

See Accessing the editor instance section.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanbotha123 picture seanbotha123  路  6Comments

apappas1129 picture apappas1129  路  6Comments

csimpi picture csimpi  路  5Comments

ma2ciek picture ma2ciek  路  9Comments

maximelafarie picture maximelafarie  路  4Comments