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 #105 from ckeditor/t/95a
Browse files Browse the repository at this point in the history
Fix: Link Plugin should manage focus when the balloon is open. Made Link Plugins #showPanel() and #hidePanel() methods protected. Closes #95. Closes #94.
  • Loading branch information
oleq committed Apr 14, 2017
2 parents c35c2ba + 4097be7 commit 5a83b70
Show file tree
Hide file tree
Showing 2 changed files with 321 additions and 211 deletions.
37 changes: 23 additions & 14 deletions src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,42 +237,51 @@ export default class Link extends Plugin {

/**
* Adds the {@link #formView} to the {@link #_balloon}.
* When view is already added then try to focus it `focusInput` parameter is set as true.
*
* @private
* @protected
* @param {Boolean} [focusInput=false] When `true`, link form will be focused on panel show.
* @return {Promise} A promise resolved when the {@link #formView} {@link module:ui/view~View#init} is done.
*/
_showPanel( focusInput ) {
if ( this._balloon.hasView( this.formView ) ) {
return;
}

this._balloon.add( {
view: this.formView,
position: this._getBalloonPositionData()
} );
// Check if formView should be focused and focus it if is visible.
if ( focusInput && this._balloon.visibleView === this.formView ) {
this.formView.urlInputView.select();
}

if ( focusInput ) {
this.formView.urlInputView.select();
return Promise.resolve();
}

return this._balloon.add( {
view: this.formView,
position: this._getBalloonPositionData()
} ).then( () => {
if ( focusInput ) {
this.formView.urlInputView.select();
}
} );
}

/**
* Removes the {@link #formView} from the {@link #_balloon}.
*
* @private
* See {@link #_showPanel}.
*
* @protected
* @param {Boolean} [focusEditable=false] When `true`, editable focus will be restored on panel hide.
*/
_hidePanel( focusEditable ) {
if ( !this._balloon.hasView( this.formView ) ) {
return;
}

this._balloon.remove( this.formView );
this.stopListening( this.editor.editing.view, 'render' );

if ( focusEditable ) {
this.editor.editing.view.focus();
}

this.stopListening( this.editor.editing.view, 'render' );
this._balloon.remove( this.formView );
}

/**
Expand Down
Loading

0 comments on commit 5a83b70

Please sign in to comment.