Răsfoiți Sursa

Aligned ListView to the View#render API.

Aleksander Nowodzinski 8 ani în urmă
părinte
comite
76a5e1ab13

+ 12 - 9
packages/ckeditor5-ui/src/list/listview.js

@@ -8,7 +8,6 @@
  */
 
 import View from '../view';
-import Template from '../template';
 import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
 import FocusCycler from '../focuscycler';
 import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
@@ -69,7 +68,7 @@ export default class ListView extends View {
 			}
 		} );
 
-		this.template = new Template( {
+		this.setTemplate( {
 			tag: 'ul',
 
 			attributes: {
@@ -81,6 +80,17 @@ export default class ListView extends View {
 
 			children: this.items
 		} );
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	render() {
+		super.render();
+
+		for ( const item of this.items ) {
+			this.focusTracker.add( item.element );
+		}
 
 		this.items.on( 'add', ( evt, item ) => {
 			this.focusTracker.add( item.element );
@@ -89,16 +99,9 @@ export default class ListView extends View {
 		this.items.on( 'remove', ( evt, item ) => {
 			this.focusTracker.remove( item.element );
 		} );
-	}
 
-	/**
-	 * @inheritDoc
-	 */
-	init() {
 		// Start listening for the keystrokes coming from #element.
 		this.keystrokes.listenTo( this.element );
-
-		super.init();
 	}
 
 	/**

+ 6 - 5
packages/ckeditor5-ui/tests/list/listview.js

@@ -17,7 +17,8 @@ describe( 'ListView', () => {
 	let view;
 
 	beforeEach( () => {
-		return ( view = new ListView() ).init();
+		view = new ListView();
+		view.render();
 	} );
 
 	describe( 'constructor()', () => {
@@ -26,10 +27,10 @@ describe( 'ListView', () => {
 			expect( view.element.classList.contains( 'ck-list' ) ).to.be.true;
 		} );
 
-		it( 'creates view#children collection', () => {
+		it( 'creates view#items collection', () => {
 			expect( view.items ).to.be.instanceOf( ViewCollection );
 			expect( view.template.children ).to.have.length( 1 );
-			expect( view.template.children.get( 0 ) ).to.equal( view.items );
+			expect( view.template.children[ 0 ] ).to.equal( view.items );
 		} );
 
 		it( 'creates #focusTracker instance', () => {
@@ -58,13 +59,13 @@ describe( 'ListView', () => {
 		} );
 	} );
 
-	describe( 'init()', () => {
+	describe( 'render()', () => {
 		it( 'starts listening for #keystrokes coming from #element', () => {
 			view = new ListView();
 
 			const spy = sinon.spy( view.keystrokes, 'listenTo' );
 
-			view.init();
+			view.render();
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledWithExactly( spy, view.element );
 		} );