From 663169f040b40fae081af3c565ed7f0ae6e53bc0 Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Fri, 19 Apr 2019 18:01:48 +0800 Subject: [PATCH] feat(module:form): support hide the label colon (#3136) --- components/form/doc/index.en-US.md | 2 + components/form/doc/index.zh-CN.md | 2 + components/form/nz-form-item.component.ts | 36 ++++---- components/form/nz-form-label.component.html | 4 +- components/form/nz-form-label.component.ts | 22 ++++- components/form/nz-form-label.spec.ts | 11 ++- components/form/nz-form.directive.ts | 55 +++++++++++- components/form/nz-form.spec.ts | 92 +++++++++++++++++++- 8 files changed, 198 insertions(+), 26 deletions(-) diff --git a/components/form/doc/index.en-US.md b/components/form/doc/index.en-US.md index b094ec58e93..94fe9030e1e 100644 --- a/components/form/doc/index.en-US.md +++ b/components/form/doc/index.en-US.md @@ -59,6 +59,7 @@ import { NzFormModule } from 'ng-zorro-antd'; | Property | Description | Type | Default Value | | -------- | ----------- | ---- | ------------- | | `[nzLayout]`| Form layout | `'horizontal'|'vertical'|'inline'` | `'horizontal'` | +| `[nzNoColon]`| change default props `[nzNoColon]` value of `nz-form-label` | `boolean` | `false` | ### nz-form-item @@ -80,6 +81,7 @@ The label of the form item, optional. | Property | Description | Type | Default Value | | --- | --- | --- | --- | | `[nzRequired]`| add required style to current item | `boolean` | `false` | +| `[nzNoColon]`| whether to not display `:` after label text. | `boolean` | `false` | | `[nzFor]`| The `for` property of `label` | `string` | - | | `[nzColon]` | Used with `label`, whether to display `:` after label text. | `boolean` | `true` | diff --git a/components/form/doc/index.zh-CN.md b/components/form/doc/index.zh-CN.md index 0fea22522bc..8893d5f4665 100644 --- a/components/form/doc/index.zh-CN.md +++ b/components/form/doc/index.zh-CN.md @@ -57,6 +57,7 @@ import { NzFormModule } from 'ng-zorro-antd'; | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | `[nzLayout]`| 表单布局 | `'horizontal'|'vertical'|'inline'` | `'horizontal'` | +| `[nzNoColon]`| 配置 `nz-form-label` 的 `[nzNoColon]` 的默认值 | `boolean` | `false` | ### nz-form-item @@ -77,6 +78,7 @@ import { NzFormModule } from 'ng-zorro-antd'; | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | `[nzRequired]`| 当前项是否为必填,仅影响样式 | `boolean` | `false` | +| `[nzNoColon]`| 是否不显示 label 后面的冒号 | `boolean` | `false` | | `[nzFor]`| label 标签的 for 属性 | `string` | - | | `[nzColon]` | 配合 label 属性使用,表示是否显示 label 后面的冒号 | `boolean` | `true` | diff --git a/components/form/nz-form-item.component.ts b/components/form/nz-form-item.component.ts index 6aff9460c28..667c35c39cf 100644 --- a/components/form/nz-form-item.component.ts +++ b/components/form/nz-form-item.component.ts @@ -9,14 +9,16 @@ import { ElementRef, Input, NgZone, + OnChanges, OnDestroy, QueryList, Renderer2, + SimpleChanges, ViewEncapsulation } from '@angular/core'; import { takeUntil } from 'rxjs/operators'; -import { toBoolean, NzUpdateHostClassService } from 'ng-zorro-antd/core'; +import { InputBoolean, NzUpdateHostClassService } from 'ng-zorro-antd/core'; import { NzRowDirective } from 'ng-zorro-antd/grid'; import { NzFormExplainComponent } from './nz-form-explain.component'; @@ -31,7 +33,7 @@ import { NzFormExplainComponent } from './nz-form-explain.component'; providers: [NzUpdateHostClassService], templateUrl: './nz-form-item.component.html', host: { - '[class.ant-form-item-with-help]': 'listOfNzFormExplainComponent && (listOfNzFormExplainComponent.length>0)' + '[class.ant-form-item-with-help]': 'listOfNzFormExplainComponent && (listOfNzFormExplainComponent.length > 0)' }, styles: [ ` @@ -41,21 +43,11 @@ import { NzFormExplainComponent } from './nz-form-explain.component'; ` ] }) -export class NzFormItemComponent extends NzRowDirective implements AfterContentInit, OnDestroy { - private _flex = false; - @ContentChildren(NzFormExplainComponent, { descendants: true }) listOfNzFormExplainComponent: QueryList< - NzFormExplainComponent - >; +export class NzFormItemComponent extends NzRowDirective implements AfterContentInit, OnDestroy, OnChanges { + @Input() @InputBoolean() nzFlex: boolean = false; - @Input() - set nzFlex(value: boolean) { - this._flex = toBoolean(value); - if (this._flex) { - this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'flex'); - } else { - this.renderer.removeStyle(this.elementRef.nativeElement, 'display'); - } - } + @ContentChildren(NzFormExplainComponent, { descendants: true }) + listOfNzFormExplainComponent: QueryList; constructor( elementRef: ElementRef, @@ -77,4 +69,16 @@ export class NzFormItemComponent extends NzRowDirective implements AfterContentI }); } } + + ngOnChanges(changes: SimpleChanges): void { + super.ngOnChanges(changes); + if (changes.hasOwnProperty('nzFlex')) { + const flex = changes.nzFlex.currentValue; + if (flex) { + this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'flex'); + } else { + this.renderer.removeStyle(this.elementRef.nativeElement, 'display'); + } + } + } } diff --git a/components/form/nz-form-label.component.html b/components/form/nz-form-label.component.html index 03ee17af61c..4de8989fb4c 100644 --- a/components/form/nz-form-label.component.html +++ b/components/form/nz-form-label.component.html @@ -1,3 +1,5 @@ -