8
0
Просмотр исходного кода

Blur text alternative input before removing it only when form was focused.

Oskar Wróbel 6 лет назад
Родитель
Сommit
a2d7c4d8e7

+ 4 - 2
packages/ckeditor5-image/src/imagetextalternative/imagetextalternativeui.js

@@ -193,7 +193,9 @@ export default class ImageTextAlternativeUI extends Plugin {
 
 		// Blur the input element before removing it from DOM to prevent issues in some browsers.
 		// See https://github.com/ckeditor/ckeditor5/issues/1501.
-		this._form.saveButtonView.focus();
+		if ( this._form.focusTracker.isFocused ) {
+			this._form.saveButtonView.focus();
+		}
 
 		this._balloon.remove( this._form );
 
@@ -209,6 +211,6 @@ export default class ImageTextAlternativeUI extends Plugin {
 	 * @type {Boolean}
 	 */
 	get _isVisible() {
-		return this._balloon.visibleView == this._form;
+		return this._balloon.visibleView === this._form;
 	}
 }

+ 17 - 0
packages/ckeditor5-image/tests/imagetextalternative/imagetextalternativeui.js

@@ -169,11 +169,28 @@ describe( 'ImageTextAlternativeUI', () => {
 			const editableFocusSpy = sinon.spy( editor.editing.view, 'focus' );
 			const buttonFocusSpy = sinon.spy( form.saveButtonView, 'focus' );
 
+			form.focusTracker.isFocused = true;
+
 			form.fire( 'submit' );
 
 			expect( buttonFocusSpy.calledBefore( editableFocusSpy ) ).to.equal( true );
 		} );
 
+		// https://github.com/ckeditor/ckeditor5-image/issues/299
+		it( 'should not blur url input element before hiding the view when view was not focused', () => {
+			setData( model, '[<image src="" alt="foo bar"></image>]' );
+
+			editor.ui.componentFactory.create( 'imageTextAlternative' ).fire( 'execute' );
+
+			const buttonFocusSpy = sinon.spy( form.saveButtonView, 'focus' );
+
+			form.focusTracker.isFocused = false;
+
+			form.fire( 'cancel' );
+
+			sinon.assert.notCalled( buttonFocusSpy );
+		} );
+
 		describe( 'integration with the editor selection (ui#update event)', () => {
 			it( 'should re-position the form', () => {
 				setData( model, '[<image src=""></image>]' );