Skip to content

Commit

Permalink
Expose onBlur callback for address fields (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
slwen authored and noweverywhere committed Dec 11, 2016
1 parent 8bb3674 commit 7e96c7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions forms/AddressFieldset/__tests__/AddressFieldset-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

import { mount } from 'enzyme'
import AddressFieldset from '../'
let fakeAddress = {
street_address: '123 Fakerton Drive',
Expand Down Expand Up @@ -34,4 +35,18 @@ describe('AddressFieldset', () => {
})
})
})

it('calls an onBlur callback when a given field is blurred', () => {
const onBlurSpy = sinon.spy()
const wrapper = mount(
<AddressFieldset
address={fakeAddress}
onBlur={onBlurSpy} />
)
const streetInput = wrapper.find('#street_address')
streetInput.simulate('blur')

expect(onBlurSpy).to.have.been.calledOnce
expect(onBlurSpy).to.have.been.calledWith('street_address', '123 Fakerton Drive')
})
})
3 changes: 2 additions & 1 deletion forms/AddressFieldset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default React.createClass({
validations: {},
onCountrySelect: () => {},
onChange: () => {},
onError: () => {}
onError: () => {},
onBlur: null
}
},

Expand Down
3 changes: 2 additions & 1 deletion mixins/formControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default {
return {
onChange: this.onFieldChange(name),
onUnmount: this.onFieldUnmount(name),
onError: this.onFieldError(name)
onError: this.onFieldError(name),
onBlur: this.props.onBlur && this.props.onBlur.bind(null, name)
}
},

Expand Down

0 comments on commit 7e96c7d

Please sign in to comment.