Skip to content

Commit

Permalink
fix(abc:se): fix ingored set id when control invalid controlAccessor (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Jun 30, 2020
1 parent f4abe81 commit e205c4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/abc/se/se.component.ts
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion packages/abc/se/se.spec.ts
Expand Up @@ -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';
Expand All @@ -21,7 +22,7 @@ describe('abc: edit', () => {

const moduleAction = () => {
TestBed.configureTestingModule({
imports: [SEModule, FormsModule, NoopAnimationsModule],
imports: [SEModule, FormsModule, NzRadioModule, NoopAnimationsModule],
declarations: [TestComponent],
});
};
Expand Down Expand Up @@ -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(`
<form nz-form se-container>
<se label="a">
<nz-radio-group [(ngModel)]="val" name="val">
<label nz-radio nzValue=""></label>
</nz-radio-group>
</se>
</form>
`);
expect(page.getEl('nz-radio-group').getAttribute('for')).toBeNull();
});
it(`should be keeping placeholder when content is empty`, () => {
genModule(`
<form nz-form se-container>
Expand Down

0 comments on commit e205c4d

Please sign in to comment.