Skip to content

Commit

Permalink
fix(DatePicker): call onChange on Done button (#2089)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmaillet authored and jsomsanith-tlnd committed Apr 1, 2019
1 parent 65dd402 commit f7aae7c
Showing 1 changed file with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ import {
INPUT_ERRORS,
} from '../constants';

function haveErrorsChanged(oldErrors, newErrors) {
if (oldErrors.length !== newErrors.length) {
return true;
}

const oldErrorMessages = oldErrors.map(error => error.message);
return newErrors.some(error => !oldErrorMessages.includes(error.message));
}

class ContextualManager extends React.Component {
static displayName = 'DateTime.Manager';
static propTypes = {
Expand Down Expand Up @@ -103,16 +94,13 @@ class ContextualManager extends React.Component {
}

onChange(event, origin) {
const { errorMessage, datetime, textInput, errors, previousErrors } = this.state;

if (
this.props.onChange &&
(this.dateHasChanged() || haveErrorsChanged(previousErrors, errors))
) {
// we need to update the initial state once it has been changed
this.initialState = { ...this.state };
this.props.onChange(event, { errors, errorMessage, datetime, textInput, origin });
if (!this.props.onChange) {
return;
}
const { errorMessage, datetime, textInput, errors } = this.state;
// we need to update the initial state once it has been changed
this.initialState = { ...this.state };
this.props.onChange(event, { errors, errorMessage, datetime, textInput, origin });
}

onInputChange(event) {
Expand Down Expand Up @@ -224,13 +212,6 @@ class ContextualManager extends React.Component {
return !!this.state.errors.find(stateError => errorCodesArray.indexOf(stateError.code) > -1);
}

dateHasChanged() {
const datetime = this.state.datetime;
return (
datetime !== this.initialState.datetime && !isSameSecond(datetime, this.initialState.datetime)
);
}

render() {
return (
<DateTimeContext.Provider
Expand Down

0 comments on commit f7aae7c

Please sign in to comment.