Browse Source

Added #content collection to FloatingPanelView.

Aleksander Nowodzinski 8 years ago
parent
commit
d78bc30fc7

+ 11 - 1
packages/ckeditor5-ui/src/panel/floating/floatingpanelview.js

@@ -67,6 +67,14 @@ export default class FloatingPanelView extends View {
 		 */
 		this.set( 'targetElement', null );
 
+		/**
+		 * Collection of the child views which creates balloon panel contents.
+		 *
+		 * @readonly
+		 * @member {module:ui/viewcollection~ViewCollection}
+		 */
+		this.content = this.createCollection();
+
 		this.template = new Template( {
 			tag: 'div',
 			attributes: {
@@ -78,7 +86,9 @@ export default class FloatingPanelView extends View {
 					top: bind.to( 'top', toPx ),
 					left: bind.to( 'left', toPx ),
 				}
-			}
+			},
+
+			children: this.content
 		} );
 	}
 

+ 18 - 1
packages/ckeditor5-ui/tests/panel/floating/floatingpanelview.js

@@ -3,11 +3,12 @@
  * For licensing, see LICENSE.md.
  */
 
-/* global Event */
+/* global document, Event */
 
 import global from '@ckeditor/ckeditor5-utils/src/dom/global';
 import FloatingPanelView from '../../../src/panel/floating/floatingpanelview';
 import View from '../../../src/view';
+import ViewCollection from '../../../src/viewcollection';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import * as positionUtils from '@ckeditor/ckeditor5-utils/src/dom/position';
 
@@ -62,6 +63,10 @@ describe( 'FloatingPanelView', () => {
 
 			expect( view.targetElement ).to.be.null;
 		} );
+
+		it( 'creates view#content collection', () => {
+			expect( view.content ).to.be.instanceOf( ViewCollection );
+		} );
 	} );
 
 	describe( 'template', () => {
@@ -91,6 +96,18 @@ describe( 'FloatingPanelView', () => {
 					expect( view.element.style.left ).to.equal( '20px' );
 				} );
 			} );
+
+			describe( 'children', () => {
+				it( 'should react on view#content', () => {
+					expect( view.element.childNodes.length ).to.equal( 0 );
+
+					const item = new View();
+					item.element = document.createElement( 'div' );
+					view.content.add( item );
+
+					expect( view.element.childNodes.length ).to.equal( 1 );
+				} );
+			} );
 		} );
 	} );