浏览代码

Blur url input element before hiding the link view.

Oskar Wróbel 6 年之前
父节点
当前提交
5ce16b5081
共有 2 个文件被更改,包括 17 次插入0 次删除
  1. 5 0
      packages/ckeditor5-link/src/linkui.js
  2. 12 0
      packages/ckeditor5-link/tests/linkui.js

+ 5 - 0
packages/ckeditor5-link/src/linkui.js

@@ -306,6 +306,11 @@ export default class LinkUI extends Plugin {
 	 */
 	_removeFormView() {
 		if ( this._isFormInPanel ) {
+			// Blur the input element before removing it from DOM.
+			// See https://github.com/ckeditor/ckeditor5/issues/1501.
+			// Focusing editable before removing FormView makes balloon flickering.
+			this.formView.saveButtonView.focus();
+
 			this._balloon.remove( this.formView );
 
 			// Because the form has an input which has focus, the focus must be brought back

+ 12 - 0
packages/ckeditor5-link/tests/linkui.js

@@ -829,6 +829,18 @@ describe( 'LinkUI', () => {
 				expect( balloon.visibleView ).to.equal( actionsView );
 				expect( focusEditableSpy.calledOnce ).to.be.true;
 			} );
+
+			// https://github.com/ckeditor/ckeditor5/issues/1501
+			it( 'should blur url input element before hiding the view', () => {
+				linkUIFeature._showUI();
+
+				const focusSpy = testUtils.sinon.spy( formView.saveButtonView, 'focus' );
+				const removeSpy = testUtils.sinon.spy( balloon, 'remove' );
+
+				formView.fire( 'cancel' );
+
+				expect( focusSpy.calledBefore( removeSpy ) ).to.equal( true );
+			} );
 		} );
 	} );
 } );