Skip to content

Commit 19cd709

Browse files
jnm2377emyarodkodiakhq[bot]
authored
fix(NumberInput): pass down event change value (#8243)
* fix: pass value to onChange handler * chore: add example to story * Update packages/react/src/components/NumberInput/NumberInput-story.js Co-authored-by: emyarod <emyarod@users.noreply.github.com> * Update packages/react/src/components/NumberInput/NumberInput-story.js Co-authored-by: emyarod <emyarod@users.noreply.github.com> * fix: pass value without breaking change * fix: use num input props for story * fix: add props back to numinput * chore: update num test * Update packages/react/src/components/NumberInput/NumberInput-story.js Co-authored-by: emyarod <emyarod@users.noreply.github.com> * fix: return same data for events * chore: update num input test * chore: remove duplicate prop * fix: revert story changes Co-authored-by: emyarod <emyarod@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 7c43501 commit 19cd709

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/react/src/components/NumberInput/NumberInput-test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,10 @@ describe('NumberInput', () => {
411411
});
412412

413413
it('should invoke onClick when up arrow is clicked', () => {
414+
wrapper.setProps({ value: 1 });
414415
upArrow.simulate('click');
415416
expect(onClick).toBeCalled();
416-
expect(onClick).toHaveBeenCalledWith(expect.anything(), 'up');
417+
expect(onClick).toHaveBeenCalledWith(expect.anything(), 'up', 2);
417418
});
418419

419420
it('should only increase the value on up arrow click if value is less than max', () => {
@@ -466,13 +467,16 @@ describe('NumberInput', () => {
466467
downArrow.simulate('click');
467468
expect(onClick).toBeCalled();
468469
expect(onChange).toBeCalled();
469-
expect(onClick).toHaveBeenCalledWith(expect.anything(), 'down');
470+
expect(onClick).toHaveBeenCalledWith(expect.anything(), 'down', 0);
470471
});
471472

472473
it('should invoke onChange when numberInput is changed', () => {
473474
input.simulate('change');
474475
expect(onChange).toBeCalled();
475-
expect(onChange).toHaveBeenCalledWith(expect.anything());
476+
expect(onChange).toHaveBeenCalledWith(
477+
expect.anything(),
478+
expect.anything()
479+
);
476480
});
477481
});
478482
});

packages/react/src/components/NumberInput/NumberInput.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,18 @@ class NumberInput extends Component {
249249
if (!disabled) {
250250
evt.persist();
251251
evt.imaginaryTarget = this._inputRef;
252+
const prevValue = this.state.value;
252253
const value = evt.target.value;
254+
const direction = prevValue < value ? 'up' : 'down';
253255
this.setState(
254256
{
255257
value,
256258
},
257259
() => {
258260
if (useControlledStateWithValue) {
259-
onChange(evt, { value });
261+
onChange(evt, { value, direction });
260262
} else if (onChange) {
261-
onChange(evt);
263+
onChange(evt, { value, direction });
262264
}
263265
}
264266
);
@@ -286,12 +288,14 @@ class NumberInput extends Component {
286288
value,
287289
},
288290
() => {
291+
//TO-DO v11: update these events to return the same things --> evt, {value, direction}
289292
if (useControlledStateWithValue) {
290293
onClick && onClick(evt, { value, direction });
291294
onChange && onChange(evt, { value, direction });
292295
} else {
293-
onClick && onClick(evt, direction);
294-
onChange && onChange(evt, direction);
296+
// value added as a 3rd argument rather than in same obj so it doesn't break in v10
297+
onClick && onClick(evt, direction, value);
298+
onChange && onChange(evt, direction, value);
295299
}
296300
}
297301
);

0 commit comments

Comments
 (0)