Skip to content

Commit 71c083c

Browse files
authored
fix(Input): use e.target.value in onChange data.value (#853)
1 parent 6d11e89 commit 71c083c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/elements/Input/Input.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Input extends Component {
116116
/** An Icon Input field can show that it is currently loading data */
117117
loading: PropTypes.bool,
118118

119-
/** Called with (e, props) on change. */
119+
/** Called with (e, data) on change. */
120120
onChange: PropTypes.func,
121121

122122
/** An Input can vary in size */
@@ -137,7 +137,12 @@ class Input extends Component {
137137

138138
handleChange = (e) => {
139139
const { onChange } = this.props
140-
if (onChange) onChange(e, this.props)
140+
if (onChange) {
141+
onChange(e, {
142+
...this.props,
143+
value: _.get(e, 'target.value'),
144+
})
145+
}
141146
}
142147

143148
render() {

test/specs/elements/Input/Input-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ describe('Input', () => {
7373
})
7474

7575
describe('onChange', () => {
76-
it('is called with (event, props) on change', () => {
76+
it('is called with (e, data) on change', () => {
7777
const spy = sandbox.spy()
78-
const event = { fake: 'event' }
78+
const e = { target: { value: 'name' } }
7979
const props = { 'data-foo': 'bar', onChange: spy }
8080

8181
const wrapper = shallow(<Input {...props} />)
8282

83-
wrapper.find('input').simulate('change', event)
83+
wrapper.find('input').simulate('change', e)
8484

8585
spy.should.have.been.calledOnce()
86-
spy.should.have.been.calledWithMatch(event, props)
86+
spy.should.have.been.calledWithMatch(e, { ...props, value: e.target.value })
8787
})
8888
})
8989
})

0 commit comments

Comments
 (0)