Skip to content

Commit 2b4df9a

Browse files
authored
fix(module:radio): invalid disable state (#7812)
1 parent 532d6ef commit 2b4df9a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

components/radio/radio.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ export class NzRadioComponent implements ControlValueAccessor, AfterViewInit, On
145145
this.cdr.markForCheck();
146146
});
147147
this.nzRadioService.disabled$.pipe(takeUntil(this.destroy$)).subscribe(disabled => {
148-
this.nzDisabled = disabled;
148+
this.nzDisabled = (this.isNzDisableFirstChange && this.nzDisabled) || disabled;
149+
this.isNzDisableFirstChange = false;
149150
this.cdr.markForCheck();
150151
});
151152
this.nzRadioService.selected$.pipe(takeUntil(this.destroy$)).subscribe(value => {

components/radio/radio.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,13 @@ describe('radio', () => {
313313
const radioGroup: NzRadioGroupComponent = fixture.debugElement.query(
314314
By.directive(NzRadioGroupComponent)
315315
).componentInstance;
316+
const radios = fixture.debugElement.queryAll(By.directive(NzRadioComponent));
317+
const [firstRadios] = radios;
316318
expect(testComponent.formGroup.valid).toBe(true);
317319
expect(testComponent.formGroup.pristine).toBe(true);
318320
expect(testComponent.formGroup.touched).toBe(false);
319321
expect(radioGroup.nzDisabled).toBeFalsy();
322+
expect(firstRadios.componentInstance.nzDisabled).toBeTruthy();
320323
}));
321324
it('should be disable if form is disable and nzDisable set to false initially', fakeAsync(() => {
322325
testComponent.formGroup.disable();
@@ -513,7 +516,7 @@ export class NzTestRadioFormComponent {
513516
template: `
514517
<form [formGroup]="formGroup">
515518
<nz-radio-group formControlName="radioGroup" [nzDisabled]="nzDisabled">
516-
<label nz-radio-button nzValue="A">A</label>
519+
<label nz-radio-button nzValue="A" [nzDisabled]="true">A</label>
517520
<label nz-radio-button nzValue="B">B</label>
518521
<label nz-radio-button nzValue="C">C</label>
519522
<label nz-radio-button nzValue="D">D</label>

0 commit comments

Comments
 (0)