瀏覽代碼

Revert the code before major changes

panr 5 年之前
父節點
當前提交
9d2b400a5d

+ 4 - 34
packages/ckeditor5-ui/src/formheader/formheaderview.js

@@ -15,9 +15,7 @@ import '../../theme/components/formheader/formheader.css';
  * The class component representing a form header view. It should be used in more advanced forms to
  * describe the main purpose of the form.
  *
- * By default the component contains an optional bolded label view, which text can be set through the options (`[options.label]`),
- * while creating the component. The label text is usually a short (at most 3-word) string. If the label text isn't defined
- * the label view will not appear.
+ * By default the component contains a bolded label view that has to be set. The label is usually a short (at most 3-word) string.
  * The component can also be extended by any other elements, like: icons, dropdowns, etc.
  *
  * It is used i.a.
@@ -78,15 +76,9 @@ export default class FormHeaderView extends View {
 			children: this.children
 		} );
 
-		/**
-		 * A label view, which text can be set through `options.label` or {@link #label}.
-		 *
-		 * @readonly
-		 * @member {module:ui/view~View}
-		 */
-		this.labelView = new View( locale );
+		const label = new View( locale );
 
-		this.labelView.setTemplate( {
+		label.setTemplate( {
 			tag: 'span',
 			attributes: {
 				class: [
@@ -99,28 +91,6 @@ export default class FormHeaderView extends View {
 			]
 		} );
 
-		this.label && this.children.add( this.labelView );
-
-		this.on( 'set:label', () => {
-			if ( !this.children.has( this.labelView ) ) {
-				this.children.add( this.labelView );
-			}
-		} );
-	}
-
-	render() {
-		super.render();
-
-		this.on( 'change:label', evt => {
-			if ( this.children.has( this.labelView ) ) {
-				if ( !evt.source.label ) {
-					// Remove the label view if it is no longer necessary (eg.: label text is empty).
-					this.children.remove( this.labelView );
-				}
-			} else {
-				// Append label view only if it has not been added while creating the instance, but after render.
-				this.children.add( this.labelView );
-			}
-		} );
+		this.children.add( label );
 	}
 }

+ 2 - 21
packages/ckeditor5-ui/tests/formheader/formheaderview.js

@@ -17,9 +17,7 @@ describe( 'FormHeaderView', () => {
 	} );
 
 	afterEach( () => {
-		if ( view.element ) {
-			view.element.remove();
-		}
+		view.element.remove();
 	} );
 
 	describe( 'constructor()', () => {
@@ -29,24 +27,7 @@ describe( 'FormHeaderView', () => {
 
 		it( 'should create view#children collection', () => {
 			expect( view.children ).to.be.instanceOf( ViewCollection );
-			expect( view.children ).to.have.length( 0 );
-		} );
-
-		it( 'should contain label view only when view#label is defined', () => {
-			view = new FormHeaderView( locale, {
-				label: 'Foo label'
-			} );
-
-			view.render();
-
-			expect( view.children ).to.be.instanceOf( ViewCollection );
 			expect( view.children ).to.have.length( 1 );
-
-			expect( view.children.first.element.classList.contains( 'ck-form__header__label' ) ).to.be.true;
-
-			view.label = '';
-
-			expect( view.children ).to.have.length( 0 );
 		} );
 
 		it( 'should set view#label', () => {
@@ -108,7 +89,7 @@ describe( 'FormHeaderView', () => {
 
 				view.children.add( child );
 
-				expect( view.element.childNodes[ 0 ] ).to.equal( child.element );
+				expect( view.element.childNodes[ 1 ] ).to.equal( child.element );
 
 				view.destroy();
 			} );