Skip to content

Commit

Permalink
Merge pull request #258 from appfolio/addDateInputOnBlur
Browse files Browse the repository at this point in the history
gt - Add onBlur prop to DateInput
  • Loading branch information
gthomas-appfolio authored Jul 7, 2017
2 parents 1530d2c + 8cb7e88 commit 5727a63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class DateInput extends Component {
React.PropTypes.object
]),
keyboard: React.PropTypes.bool,
onBlur: React.PropTypes.func,
onChange: React.PropTypes.func,
showOnFocus: React.PropTypes.bool,
disabled: React.PropTypes.bool,
Expand All @@ -69,6 +70,7 @@ export default class DateInput extends Component {
className: '',
dateFormat: 'M/D/YYYY',
keyboard: true,
onBlur: () => {},
onChange: () => {},
showOnFocus: true,
disabled: false
Expand Down Expand Up @@ -173,7 +175,7 @@ export default class DateInput extends Component {
toggle = () => (this.state.open ? this.close() : this.show());

render() {
const { className, disabled, showOnFocus } = this.props;
const { className, disabled, onBlur, showOnFocus } = this.props;
const { open } = this.state;
const value = this.getCurrentValue();
const date = this.getCurrentDate();
Expand All @@ -186,6 +188,7 @@ export default class DateInput extends Component {
<Input
type="text"
value={value}
onBlur={onBlur}
onChange={this.onChange}
onClick={showOnFocus && this.show}
onFocus={showOnFocus && this.show}
Expand Down
1 change: 1 addition & 0 deletions stories/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ storiesOf('DateInput', module)
dateFormat={text('dateFormat', DateInput.defaultProps.dateFormat)}
showOnFocus={boolean('showOnFocus', DateInput.defaultProps.showOnFocus)}
disabled={boolean('disabled', DateInput.defaultProps.disabled)}
onBlur={action('onBlur')}
onChange={action('onChange')}
/>
</div>
Expand Down
8 changes: 8 additions & 0 deletions test/components/DateInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ describe('<DateInput />', () => {
input.simulate('change', { target: { value: 'Grape Jelly' } });
assert(callback.calledWith('Grape Jelly', false));
});

it('should should call onBlur after losing focus', () => {
const callback = sinon.spy();
const component = mount(<DateInput onBlur={callback} />);
const input = component.find('input');
input.simulate('blur');
assert(callback.calledOnce);
});
});

context('date picker', () => {
Expand Down

0 comments on commit 5727a63

Please sign in to comment.