From ca2d7e0f647cf9a9308aea9a796a33d193ecf102 Mon Sep 17 00:00:00 2001 From: VTHINKXIE Date: Sun, 22 Jul 2018 17:00:50 +0800 Subject: [PATCH] fix(module:input): mix using addon and affix (#1857) close #1795 --- .../input/nz-input-group.component.html | 40 +++++++++++-------- components/input/nz-input-group.component.ts | 12 ++++-- components/input/nz-input.spec.ts | 26 +++++++++++- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/components/input/nz-input-group.component.html b/components/input/nz-input-group.component.html index 44a953ebbcb..0ec50b7f4f0 100644 --- a/components/input/nz-input-group.component.html +++ b/components/input/nz-input-group.component.html @@ -6,7 +6,10 @@ - + + + + {{ nzAddOnAfter }} @@ -15,22 +18,25 @@ - - - - {{ nzPrefix }} - - - - - - - - {{ nzSuffix }} - - - - + + + + + + + {{ nzPrefix }} + + + + + + + + {{ nzSuffix }} + + + + diff --git a/components/input/nz-input-group.component.ts b/components/input/nz-input-group.component.ts index fcd98dc7ae6..3262ccda137 100644 --- a/components/input/nz-input-group.component.ts +++ b/components/input/nz-input-group.component.ts @@ -117,9 +117,13 @@ export class NzInputGroupComponent implements AfterContentInit { return this.nzSize === 'small'; } - @HostBinding('class.ant-input-affix-wrapper') get isAffix(): boolean { - return !!(this.nzSuffix || this.nzPrefix || this.nzPrefixIcon || this.nzSuffixIcon); + return (!!(this.nzSuffix || this.nzPrefix || this.nzPrefixIcon || this.nzSuffixIcon)); + } + + @HostBinding('class.ant-input-affix-wrapper') + get isAffixWrapper(): boolean { + return (!!(this.nzSuffix || this.nzPrefix || this.nzPrefixIcon || this.nzSuffixIcon)) && !this.isAddOn; } @HostBinding('class.ant-input-group-wrapper') @@ -144,7 +148,7 @@ export class NzInputGroupComponent implements AfterContentInit { @HostBinding(`class.ant-input-affix-wrapper-lg`) get isLargeAffix(): boolean { - return this.isAffix && this.isLarge; + return this.isAffixWrapper && this.isLarge; } @HostBinding(`class.ant-input-search-lg`) @@ -159,7 +163,7 @@ export class NzInputGroupComponent implements AfterContentInit { @HostBinding(`class.ant-input-affix-wrapper-sm`) get isSmallAffix(): boolean { - return this.isAffix && this.isSmall; + return this.isAffixWrapper && this.isSmall; } @HostBinding(`class.ant-input-group-wrapper-sm`) diff --git a/components/input/nz-input.spec.ts b/components/input/nz-input.spec.ts index 5ff91c9d3e1..813da188ed0 100644 --- a/components/input/nz-input.spec.ts +++ b/components/input/nz-input.spec.ts @@ -15,7 +15,7 @@ describe('input', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports : [ NzInputModule, FormsModule, ReactiveFormsModule ], - declarations: [ NzTestInputWithInputComponent, NzTestInputWithTextAreaComponent, NzTestInputWithTextAreaAutoSizeStringComponent, NzTestInputWithTextAreaAutoSizeObjectComponent, NzTestInputGroupAddonComponent, NzTestInputGroupAffixComponent, NzTestInputGroupMultipleComponent, NzTestInputGroupColComponent, NzTestInputFormComponent ], + declarations: [ NzTestInputWithInputComponent, NzTestInputWithTextAreaComponent, NzTestInputWithTextAreaAutoSizeStringComponent, NzTestInputWithTextAreaAutoSizeObjectComponent, NzTestInputGroupAddonComponent, NzTestInputGroupAffixComponent, NzTestInputGroupMultipleComponent, NzTestInputGroupColComponent, NzTestInputFormComponent, NzTestInputGroupMixComponent ], providers : [] }).compileComponents(); })); @@ -321,6 +321,18 @@ describe('input', () => { expect(inputGroupElement.classList).toContain('ant-input-group'); }); }); + describe('mix', () => { + let inputGroupElement; + beforeEach(() => { + fixture = TestBed.createComponent(NzTestInputGroupMixComponent); + testComponent = fixture.debugElement.componentInstance; + fixture.detectChanges(); + inputGroupElement = fixture.debugElement.query(By.directive(NzInputGroupComponent)).nativeElement; + }); + it('should mix work', () => { + expect(inputGroupElement.querySelector('.ant-input-affix-wrapper').nextElementSibling.classList).toContain('ant-input-group-addon'); + }); + }); }); describe('input form', () => { describe('input with form', () => { @@ -427,6 +439,18 @@ export class NzTestInputGroupMultipleComponent { size = 'default'; } +/** https://github.com/NG-ZORRO/ng-zorro-antd/issues/1795 **/ +@Component({ + selector: 'nz-test-input-group-mix', + template: ` + + + + ` +}) +export class NzTestInputGroupMixComponent { +} + @Component({ selector: 'nz-test-input-group-col', template: `