Skip to content

Commit 88c26cc

Browse files
committed
datepicker onblur callback
1 parent 49b1adf commit 88c26cc

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/DatePicker/DatePicker.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,17 @@ class DatePicker extends Component {
207207

208208
clickOutside = () => {
209209
this.validateDates();
210-
this.setState({ hidden: true });
210+
this.setState({
211+
hidden: true
212+
}, () => {
213+
this.props.onBlur({
214+
date: this.state.selectedDate,
215+
formattedDate: this.state.formattedDate
216+
});
217+
});
211218
};
212219

213220
updateDate = (date) => {
214-
// console.log('Inside updateDate function. The event is: ', date);
215-
216221
if (this.props.enableRangeSelection) {
217222
if (date.length === 2) {
218223
let firstDateMonth = date[0].getMonth() + 1;
@@ -269,7 +274,7 @@ class DatePicker extends Component {
269274
render() {
270275
const { enableRangeSelection, disableWeekends, disableBeforeDate, disableAfterDate,
271276
disableWeekday, disablePastDates, disableFutureDates, blockedDates, disabledDates,
272-
compact, className, inputProps, buttonProps, ...props } = this.props;
277+
compact, className, inputProps, buttonProps, onBlur, ...props } = this.props;
273278

274279
const datePickerClasses = classnames(
275280
'fd-date-picker',
@@ -303,6 +308,8 @@ class DatePicker extends Component {
303308
<input
304309
{...inputProps}
305310
className={datePickerInputClasses}
311+
onBlur={() => onBlur({ date: this.state.selectedDate,
312+
formattedDate: this.state.formattedDate })}
306313
onChange={this.modifyDate}
307314
onClick={() => this.openCalendar('input')}
308315
onKeyPress={this.sendUpdate}
@@ -350,7 +357,12 @@ DatePicker.propTypes = {
350357
buttonProps: PropTypes.object,
351358
compact: PropTypes.bool,
352359
enableRangeSelection: PropTypes.bool,
353-
inputProps: PropTypes.object
360+
inputProps: PropTypes.object,
361+
onBlur: PropTypes.func
362+
};
363+
364+
DatePicker.defaultProps = {
365+
onBlur: () => {}
354366
};
355367

356368
DatePicker.propDescriptions = {

0 commit comments

Comments
 (0)