8
0
Pārlūkot izejas kodu

ImageBalloonPanelView element should be accessed on init method allowing to extend its template.

Szymon Kupś 9 gadi atpakaļ
vecāks
revīzija
2ff7e372a0

+ 10 - 3
packages/ckeditor5-image/src/ui/imageballoonpanelview.js

@@ -54,9 +54,6 @@ export default class ImageBalloonPanelView extends BalloonPanelView {
 		this.editor = editor;
 		const editingView = editor.editing.view;
 
-		// Let the focusTracker know about new focusable UI element.
-		editor.ui.focusTracker.add( this.element );
-
 		// Hide the balloon if editor had focus and now focus is lost.
 		this.listenTo( editor.ui.focusTracker, 'change:isFocused', ( evt, name, is, was ) => {
 			if ( was && !is ) {
@@ -85,6 +82,16 @@ export default class ImageBalloonPanelView extends BalloonPanelView {
 		}, 100 );
 	}
 
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		super.init();
+
+		// Let the focusTracker know about new focusable UI element.
+		this.editor.ui.focusTracker.add( this.element );
+	}
+
 	/**
 	 * Attaches the panel and enables `scroll` and `resize` listeners.
 	 */

+ 3 - 1
packages/ckeditor5-image/tests/ui/imageballoonpanelview.js

@@ -36,10 +36,12 @@ describe( 'ImageBalloonPanel', () => {
 		return editor.destroy();
 	} );
 
-	it( 'should add element to editor\'s focus tracker', () => {
+	it( 'should add element to editor\'s focus tracker after init', () => {
 		const spy = sinon.spy( editor.ui.focusTracker, 'add' );
 		const panel = new ImageBalloonPanel( editor );
 
+		sinon.assert.notCalled( spy );
+		panel.init();
 		sinon.assert.calledOnce( spy );
 		sinon.assert.calledWithExactly( spy, panel.element );
 	} );