@@ -6,9 +6,9 @@ export interface CKEditorApi {
66 focus ( ) : void ;
77 /**
88 * Imperatively sets the text in the editor.
9- *
9+ *
1010 * Prefer setting `currentValue` prop where possible.
11- *
11+ *
1212 * @param text text to set in the editor
1313 */
1414 setText ( text : string ) : void ;
@@ -27,15 +27,16 @@ interface CKEditorOpts {
2727 onClick ?: ( e : MouseEvent , pos ?: ModelPosition | null ) => void ;
2828 onKeyDown ?: ( e : KeyboardEvent ) => void ;
2929 onBlur ?: ( ) => void ;
30+ onInitialized ?: ( editorInstance : CKTextEditor ) => void ;
3031}
3132
32- export default function CKEditor ( { apiRef, currentValue, editor, config, disableNewlines, disableSpellcheck, onChange, onClick, ...restProps } : CKEditorOpts ) {
33- const editorContainerRef = useRef < HTMLDivElement > ( null ) ;
33+ export default function CKEditor ( { apiRef, currentValue, editor, config, disableNewlines, disableSpellcheck, onChange, onClick, onInitialized , ...restProps } : CKEditorOpts ) {
34+ const editorContainerRef = useRef < HTMLDivElement > ( null ) ;
3435 const textEditorRef = useRef < CKTextEditor > ( null ) ;
3536 useImperativeHandle ( apiRef , ( ) => {
3637 return {
3738 focus ( ) {
38- editorContainerRef . current ?. focus ( ) ;
39+ textEditorRef . current ?. editing . view . focus ( ) ;
3940 textEditorRef . current ?. model . change ( ( writer ) => {
4041 const documentRoot = textEditorRef . current ?. editing . model . document . getRoot ( ) ;
4142 if ( documentRoot ) {
@@ -83,6 +84,8 @@ export default function CKEditor({ apiRef, currentValue, editor, config, disable
8384 if ( currentValue ) {
8485 textEditor . setData ( currentValue ) ;
8586 }
87+
88+ onInitialized ?.( textEditor ) ;
8689 } ) ;
8790 } , [ ] ) ;
8891
@@ -103,4 +106,4 @@ export default function CKEditor({ apiRef, currentValue, editor, config, disable
103106 { ...restProps }
104107 />
105108 )
106- }
109+ }
0 commit comments