Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from ckeditor/t/42
Browse files Browse the repository at this point in the history
Fix: Moved focus tracking setup to `ImageBalloonPanelView#init()` method to prevent too early access to the view element. Closes #42.
  • Loading branch information
Reinmar authored Feb 9, 2017
2 parents bb2a8f7 + 3c4da64 commit 985e509
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/ui/imageballoonpanelview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -85,6 +82,16 @@ export default class ImageBalloonPanelView extends BalloonPanelView {
}, 100 );
}

/**
* @inheritDoc
*/
init() {
// Let the focusTracker know about new focusable UI element.
this.editor.ui.focusTracker.add( this.element );

return super.init();
}

/**
* Attaches the panel and enables `scroll` and `resize` listeners.
*/
Expand Down
19 changes: 16 additions & 3 deletions tests/ui/imageballoonpanelview.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,25 @@ describe( 'ImageBalloonPanel', () => {
return editor.destroy();
} );

it( 'should add element to editor\'s focus tracker', () => {
it( 'init method should return a promise', () => {
const panel = new ImageBalloonPanel( editor );
const promise = panel.init();

expect( promise ).to.be.instanceof( Promise );

return promise;
} );

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.calledOnce( spy );
sinon.assert.calledWithExactly( spy, panel.element );
sinon.assert.notCalled( spy );

return panel.init().then( () => {
sinon.assert.calledOnce( spy );
sinon.assert.calledWithExactly( spy, panel.element );
} );
} );

it( 'should detach panel when focus is removed', () => {
Expand Down

0 comments on commit 985e509

Please sign in to comment.