Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:radio): fix nzDisabled in radio-group #1574

Merged
merged 1 commit into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions components/radio/nz-radio-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export class NzRadioGroupComponent implements AfterContentInit, ControlValueAcce
@Input()
set nzDisabled(value: boolean) {
this._disabled = value;
this.radios.forEach((radio) => {
radio.nzDisabled = this.nzDisabled;
});
this.updateDisabledState();
}

get nzDisabled(): boolean {
Expand All @@ -72,6 +70,12 @@ export class NzRadioGroupComponent implements AfterContentInit, ControlValueAcce
return this._name;
}

updateDisabledState(): void {
this.radios.forEach((radio) => {
radio.nzDisabled = this.nzDisabled;
});
}

updateChildrenName(): void {
if (this.nzName) {
this.radios.forEach((item) => {
Expand Down Expand Up @@ -120,6 +124,7 @@ export class NzRadioGroupComponent implements AfterContentInit, ControlValueAcce
ngAfterContentInit(): void {
this.syncCheckedValue();
this.updateChildrenName();
this.updateDisabledState();
}

writeValue(value: string): void {
Expand Down
44 changes: 43 additions & 1 deletion components/radio/nz-radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('radio', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports : [ NzRadioModule, FormsModule, ReactiveFormsModule ],
declarations: [ NzTestRadioSingleComponent, NzTestRadioButtonComponent, NzTestRadioGroupComponent, NzTestRadioFormComponent, NzTestRadioGroupFormComponent ]
declarations: [ NzTestRadioSingleComponent, NzTestRadioButtonComponent, NzTestRadioGroupComponent, NzTestRadioFormComponent, NzTestRadioGroupFormComponent, NzTestRadioGroupDisabledComponent ]
});
TestBed.compileComponents();
}));
Expand Down Expand Up @@ -155,6 +155,29 @@ describe('radio', () => {
expect(radios.every(radio => radio.nativeElement.querySelector('input').name === 'test')).toBe(true);
});
});
describe('radio group disabled', () => {
let fixture;
let testComponent;
let radios;
let radioGroup;
beforeEach(() => {
fixture = TestBed.createComponent(NzTestRadioGroupDisabledComponent);
fixture.detectChanges();
testComponent = fixture.debugElement.componentInstance;
radios = fixture.debugElement.queryAll(By.directive(NzRadioButtonComponent));
radioGroup = fixture.debugElement.query(By.directive(NzRadioGroupComponent));
});
it('should disable work', fakeAsync(() => {
fixture.detectChanges();
expect(testComponent.value).toBe('A');
radios[ 1 ].nativeElement.click();
fixture.detectChanges();
flush();
fixture.detectChanges();
expect(radios[ 1 ].nativeElement.firstElementChild.classList).not.toContain('ant-radio-button-checked');
expect(testComponent.value).toBe('A');
}));
});
describe('radio form', () => {
let fixture;
let testComponent;
Expand Down Expand Up @@ -315,3 +338,22 @@ export class NzTestRadioGroupFormComponent {
this.formGroup.disable();
}
}

/** https://github.com/NG-ZORRO/ng-zorro-antd/issues/1543 **/
@Component({
selector: 'nz-test-radio-group-disabled',
template: `
<nz-radio-group [(ngModel)]="value" [nzName]="name" [nzDisabled]="disabled" [nzSize]="size">
<label nz-radio-button nzValue="A">A</label>
<label nz-radio-button nzValue="B">B</label>
<label nz-radio-button nzValue="C">C</label>
<label nz-radio-button nzValue="D">D</label>
</nz-radio-group>`
})

export class NzTestRadioGroupDisabledComponent {
size = 'default';
value = 'A';
disabled = true;
name: string;
}