Skip to content

Commit

Permalink
fix(Input): use e.target.value in onChange data.value (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason authored Nov 14, 2016
1 parent 6d11e89 commit 71c083c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/elements/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Input extends Component {
/** An Icon Input field can show that it is currently loading data */
loading: PropTypes.bool,

/** Called with (e, props) on change. */
/** Called with (e, data) on change. */
onChange: PropTypes.func,

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

handleChange = (e) => {
const { onChange } = this.props
if (onChange) onChange(e, this.props)
if (onChange) {
onChange(e, {
...this.props,
value: _.get(e, 'target.value'),
})
}
}

render() {
Expand Down
8 changes: 4 additions & 4 deletions test/specs/elements/Input/Input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ describe('Input', () => {
})

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

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

wrapper.find('input').simulate('change', event)
wrapper.find('input').simulate('change', e)

spy.should.have.been.calledOnce()
spy.should.have.been.calledWithMatch(event, props)
spy.should.have.been.calledWithMatch(e, { ...props, value: e.target.value })
})
})
})

0 comments on commit 71c083c

Please sign in to comment.