Skip to content

Commit 2d8968d

Browse files
fix(module:input-number,checkbox): accept the disabled change from ng control (NG-ZORRO#8979)
* fix(module:input-number): accept the disabled change from ng control * fix(module:checkbox): accept the disabled change from ng control
1 parent 5d261e4 commit 2d8968d

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

components/checkbox/checkbox-group.component.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ export class NzCheckboxGroupComponent implements ControlValueAccessor {
124124
}
125125

126126
setDisabledState(disabled: boolean): void {
127-
if (!this.isDisabledFirstChange) {
128-
this.finalDisabled.set(disabled);
129-
}
127+
this.finalDisabled.set((this.isDisabledFirstChange && this.nzDisabled()) || disabled);
130128
this.isDisabledFirstChange = false;
131129
}
132130

components/checkbox/checkbox-group.spec.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ describe('checkbox group', () => {
5353
}
5454
});
5555

56+
it('should be set disabled by ng control', async () => {
57+
component.controlDisabled = true;
58+
fixture.detectChanges();
59+
await fixture.whenStable();
60+
for (const element of getOptionElements()) {
61+
expect(element.classList).toContain('ant-checkbox-wrapper-disabled');
62+
}
63+
});
64+
5665
it('should be change value', async () => {
5766
component.value = ['A'];
5867
fixture.detectChanges();
@@ -150,7 +159,15 @@ describe('checkbox group with custom layout', () => {
150159

151160
@Component({
152161
imports: [NzCheckboxModule, FormsModule],
153-
template: ` <nz-checkbox-group [nzOptions]="options" [nzName]="name" [nzDisabled]="disabled" [(ngModel)]="value" /> `
162+
template: `
163+
<nz-checkbox-group
164+
[nzOptions]="options"
165+
[nzName]="name"
166+
[nzDisabled]="disabled"
167+
[(ngModel)]="value"
168+
[disabled]="controlDisabled"
169+
/>
170+
`
154171
})
155172
class CheckboxGroupTestComponent {
156173
options: string[] | number[] | NzCheckboxOption[] = [
@@ -160,6 +177,7 @@ class CheckboxGroupTestComponent {
160177
];
161178
value: string[] = [];
162179
disabled = false;
180+
controlDisabled = false;
163181
name: string | null = null;
164182
}
165183

components/input-number/input-number.component.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ describe('Input number', () => {
218218
expect(hostElement.classList).toContain('ant-input-number-disabled');
219219
});
220220

221+
it('should be set disabled by ng control', async () => {
222+
component.controlDisabled = true;
223+
fixture.detectChanges();
224+
await fixture.whenStable();
225+
expect(hostElement.querySelector('input')!.disabled).toBeTruthy();
226+
expect(hostElement.classList).toContain('ant-input-number-disabled');
227+
});
228+
221229
it('should be set readonly', () => {
222230
component.readonly = true;
223231
fixture.detectChanges();
@@ -347,6 +355,7 @@ describe('Input number with affixes or addons', () => {
347355
[nzKeyboard]="keyboard"
348356
[nzControls]="controls"
349357
[(ngModel)]="value"
358+
[disabled]="controlDisabled"
350359
/>
351360
`
352361
})
@@ -366,6 +375,7 @@ class InputNumberTestComponent {
366375
controls = true;
367376

368377
value: number | null = null;
378+
controlDisabled = false;
369379
inputNumber = viewChild.required(NzInputNumberComponent);
370380
}
371381

components/input-number/input-number.component.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ export class NzInputNumberComponent implements OnInit, ControlValueAccessor {
341341
}
342342

343343
setDisabledState(disabled: boolean): void {
344-
if (!this.isDisabledFirstChange) {
345-
this.finalDisabled.set(disabled);
346-
}
344+
this.finalDisabled.set((this.isDisabledFirstChange && this.nzDisabled()) || disabled);
347345
this.isDisabledFirstChange = false;
348346
}
349347

0 commit comments

Comments
 (0)