From e205c4dc1d96f8eca5a36705d66bde4604a53070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=89=B2?= Date: Tue, 30 Jun 2020 12:43:09 +0800 Subject: [PATCH] fix(abc:se): fix ingored set id when control invalid controlAccessor (#975) --- packages/abc/se/se.component.ts | 10 ++++++---- packages/abc/se/se.spec.ts | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/abc/se/se.component.ts b/packages/abc/se/se.component.ts index d293a1bfa..111dce76c 100644 --- a/packages/abc/se/se.component.ts +++ b/packages/abc/se/se.component.ts @@ -148,10 +148,12 @@ export class SEComponent implements OnChanges, AfterContentInit, AfterViewInit, if (this._autoId) { const controlAccessor = this.ngControl.valueAccessor as NzSafeAny; const control = (controlAccessor?.elementRef || controlAccessor?._elementRef)?.nativeElement as HTMLElement; - if (control.id) { - this._id = control.id; - } else { - control.id = this._id; + if (!!control) { + if (control.id) { + this._id = control.id; + } else { + control.id = this._id; + } } } // auto required diff --git a/packages/abc/se/se.spec.ts b/packages/abc/se/se.spec.ts index cefa0dba3..e5d88472b 100644 --- a/packages/abc/se/se.spec.ts +++ b/packages/abc/se/se.spec.ts @@ -5,6 +5,7 @@ import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { createTestContext } from '@delon/testing'; import { REP_MAX } from '@delon/theme'; +import { NzRadioModule } from 'ng-zorro-antd/radio'; import { SEContainerComponent } from './se-container.component'; import { SEComponent } from './se.component'; import { SEModule } from './se.module'; @@ -21,7 +22,7 @@ describe('abc: edit', () => { const moduleAction = () => { TestBed.configureTestingModule({ - imports: [SEModule, FormsModule, NoopAnimationsModule], + imports: [SEModule, FormsModule, NzRadioModule, NoopAnimationsModule], declarations: [TestComponent], }); }; @@ -439,6 +440,18 @@ describe('abc: edit', () => { `); expect(page.getEl('label').getAttribute('for')).toBe(id); }); + it(`should be ingored set id when control invalid controlAccessor`, () => { + genModule(` +
+ + + + + +
+ `); + expect(page.getEl('nz-radio-group').getAttribute('for')).toBeNull(); + }); it(`should be keeping placeholder when content is empty`, () => { genModule(`