Skip to content

Commit a8efd2b

Browse files
fix(module:input-number): value out of range when hold shift key (#8936)
1 parent 6fbd22c commit a8efd2b

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

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

+28-9
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,34 @@ describe('Input number', () => {
9999
expect(component.value).toBe(0);
100100
});
101101

102-
it('should be update value through the handler with hold shift key', () => {
103-
upStepByHandler({ shiftKey: true });
104-
expect(component.value).toBe(10);
105-
upStepByHandler({ shiftKey: true });
106-
expect(component.value).toBe(20);
107-
downStepByHandler({ shiftKey: true });
108-
expect(component.value).toBe(10);
109-
downStepByHandler({ shiftKey: true });
110-
expect(component.value).toBe(0);
102+
describe('should be update value through the handler with hold shift key', () => {
103+
it('normal', () => {
104+
upStepByHandler({ shiftKey: true });
105+
expect(component.value).toBe(10);
106+
upStepByHandler({ shiftKey: true });
107+
expect(component.value).toBe(20);
108+
109+
downStepByHandler({ shiftKey: true });
110+
expect(component.value).toBe(10);
111+
downStepByHandler({ shiftKey: true });
112+
expect(component.value).toBe(0);
113+
});
114+
115+
it('with min & max', () => {
116+
component.min = -5;
117+
component.max = 5;
118+
fixture.detectChanges();
119+
120+
for (let index = 0; index < 10; index++) {
121+
upStepByHandler({ shiftKey: true });
122+
}
123+
expect(component.value).toBe(component.max);
124+
125+
for (let index = 0; index < 10; index++) {
126+
downStepByHandler({ shiftKey: true });
127+
}
128+
expect(component.value).toBe(component.min);
129+
});
111130
});
112131

113132
it('should be update value through user typing', () => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export class NzInputNumberComponent implements OnInit, ControlValueAccessor {
368368
const places = getDecimalPlaces(step);
369369
const multiple = Math.pow(10, places);
370370
// Convert floating point numbers to integers to avoid floating point math errors
371-
this.setValue((Math.round((this.value() || 0) * multiple) + Math.round(step * multiple)) / multiple);
371+
this.setValue((Math.round((this.value() || 0) * multiple) + Math.round(step * multiple)) / multiple, true);
372372

373373
this.nzOnStep.emit({
374374
type: up ? 'up' : 'down',

0 commit comments

Comments
 (0)