Skip to content

Commit f7aae7c

Browse files
lmailletjsomsanith-tlnd
authored andcommitted
fix(DatePicker): call onChange on Done button (#2089)
1 parent 65dd402 commit f7aae7c

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

packages/components/src/DateTimePickers/DateTime/Manager/Manager.component.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ import {
2424
INPUT_ERRORS,
2525
} from '../constants';
2626

27-
function haveErrorsChanged(oldErrors, newErrors) {
28-
if (oldErrors.length !== newErrors.length) {
29-
return true;
30-
}
31-
32-
const oldErrorMessages = oldErrors.map(error => error.message);
33-
return newErrors.some(error => !oldErrorMessages.includes(error.message));
34-
}
35-
3627
class ContextualManager extends React.Component {
3728
static displayName = 'DateTime.Manager';
3829
static propTypes = {
@@ -103,16 +94,13 @@ class ContextualManager extends React.Component {
10394
}
10495

10596
onChange(event, origin) {
106-
const { errorMessage, datetime, textInput, errors, previousErrors } = this.state;
107-
108-
if (
109-
this.props.onChange &&
110-
(this.dateHasChanged() || haveErrorsChanged(previousErrors, errors))
111-
) {
112-
// we need to update the initial state once it has been changed
113-
this.initialState = { ...this.state };
114-
this.props.onChange(event, { errors, errorMessage, datetime, textInput, origin });
97+
if (!this.props.onChange) {
98+
return;
11599
}
100+
const { errorMessage, datetime, textInput, errors } = this.state;
101+
// we need to update the initial state once it has been changed
102+
this.initialState = { ...this.state };
103+
this.props.onChange(event, { errors, errorMessage, datetime, textInput, origin });
116104
}
117105

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

227-
dateHasChanged() {
228-
const datetime = this.state.datetime;
229-
return (
230-
datetime !== this.initialState.datetime && !isSameSecond(datetime, this.initialState.datetime)
231-
);
232-
}
233-
234215
render() {
235216
return (
236217
<DateTimeContext.Provider

0 commit comments

Comments
 (0)