ソースを参照

Used keepAttachedTo instead of attachTo for ContextualBalloon.

Oskar Wróbel 8 年 前
コミット
74cac16113

+ 1 - 1
packages/ckeditor5-ui/src/contextualballoon.js

@@ -167,7 +167,7 @@ export default class ContextualBalloon extends Plugin {
 	 */
 	_show( view ) {
 		this.view.content.add( view );
-		this.view.attachTo( this._getBalloonPosition() );
+		this.view.keepAttachedTo( this._getBalloonPosition() );
 	}
 
 	/**

+ 18 - 1
packages/ckeditor5-ui/tests/contextualballoon.js

@@ -11,7 +11,7 @@ import Template from '../src/template';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 
-/* global document */
+/* global document, window, Event */
 
 describe( 'ContextualBalloon', () => {
 	let editor, editorElement, balloon, viewA, viewB;
@@ -102,6 +102,23 @@ describe( 'ContextualBalloon', () => {
 			expect( balloon.view.attachTo.firstCall.args[ 0 ] ).to.deep.equal( { target: 'fake' } );
 		} );
 
+		it( 'should update balloon position on scroll and resize', () => {
+			balloon.add( {
+				view: viewA,
+				position: { target: document.createElement( 'div' ) }
+			} );
+
+			sinon.assert.calledOnce( balloon.view.attachTo );
+
+			window.dispatchEvent( new Event( 'resize' ) );
+
+			sinon.assert.calledTwice( balloon.view.attachTo );
+
+			document.dispatchEvent( new Event( 'scroll' ) );
+
+			sinon.assert.calledThrice( balloon.view.attachTo );
+		} );
+
 		it( 'should throw an error when try to add the same view more than once', () => {
 			balloon.add( {
 				view: viewA,