Skip to content

Commit 7742fe3

Browse files
authored
fix: rate half value when allow half is false (#8536)
1 parent d0dbd5b commit 7742fe3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

components/rate/rate.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class NzRateComponent implements OnInit, ControlValueAccessor, OnChanges
130130
}
131131

132132
this._value = input;
133-
this.hasHalf = !Number.isInteger(input);
133+
this.hasHalf = !Number.isInteger(input) && this.nzAllowHalf;
134134
this.hoverValue = Math.ceil(input);
135135
}
136136

components/rate/rate.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,22 @@ describe('rate', () => {
6161
expect(testComponent.modelChange).toHaveBeenCalledTimes(1);
6262
}));
6363
it('should allow half work', fakeAsync(() => {
64-
testComponent.allowHalf = true;
64+
testComponent.allowHalf = false;
6565
fixture.detectChanges();
6666
expect(testComponent.value).toBe(0);
67+
testComponent.value = 3.5;
68+
fixture.detectChanges();
69+
flush();
70+
fixture.detectChanges();
71+
expect(rate.nativeElement.firstElementChild.children[3].classList).toContain('ant-rate-star-full');
72+
expect(rate.nativeElement.firstElementChild.children[4].classList).toContain('ant-rate-star-zero');
73+
flush();
74+
75+
testComponent.allowHalf = true;
76+
testComponent.value = 0;
77+
fixture.detectChanges();
78+
flush();
79+
fixture.detectChanges();
6780
rate.nativeElement.firstElementChild.children[3].firstElementChild.children[1].click();
6881
fixture.detectChanges();
6982
flush();

0 commit comments

Comments
 (0)