Explorar el Código

Merge pull request #211 from smiclea/fix-datepicker-change

Fix `DateTimePicker` event if date not changed
Dorin Paslaru hace 8 años
padre
commit
601c148164
Se han modificado 1 ficheros con 12 adiciones y 7 borrados
  1. 12 7
      src/components/molecules/DatetimePicker/index.jsx

+ 12 - 7
src/components/molecules/DatetimePicker/index.jsx

@@ -150,18 +150,13 @@ class DatetimePicker extends React.Component<Props, State> {
     let path = DomUtils.getEventPath(e)
 
     if (!this.itemMouseDown && !path.find(n => n.className === 'rdtPicker')) {
-      if (this.state.date && this.state.showPicker) {
-        this.props.onChange(this.state.date.toDate())
-      }
+      this.dispatchChange()
       this.setState({ showPicker: false })
     }
   }
 
   handleDropdownClick() {
-    if (this.state.showPicker && this.state.date) {
-      this.props.onChange(this.state.date.toDate())
-    }
-
+    this.dispatchChange()
     this.setState({ showPicker: !this.state.showPicker })
   }
 
@@ -174,6 +169,16 @@ class DatetimePicker extends React.Component<Props, State> {
     this.setState({ date })
   }
 
+  dispatchChange() {
+    if (
+      this.state.date
+      && this.state.showPicker
+      && this.state.date.toDate().getTime() !== (this.props.value && this.props.value.getTime())
+    ) {
+      this.props.onChange(this.state.date.toDate())
+    }
+  }
+
   renderDateTimePicker(timezoneDate: ?moment$Moment) {
     if (!this.state.showPicker) {
       return null