Layne Anderson
2017-01-08 583af6d199035baa66dd99bf7cbc9014e5ad0ff3
Fix Issue #202 - View Not Updating when viewMode Changed (#206)

* Fix Issue #202 - View Not Updating when viewMode Changed

* Fix issue of previous fix that improperly updated current view

* Remove errant spaces and a comma
1 files added
1 files modified
44 ■■■■■ changed files
DateTime.js 10 ●●●● patch | view | raw | blame | history
example/viewModeChangeExample.js 34 ●●●●● patch | view | raw | blame | history
DateTime.js
@@ -157,18 +157,22 @@
        ;
        if ( nextProps.value !== this.props.value ||
            formats.datetime !== this.getFormats( this.props ).datetime ){
            formats.datetime !== this.getFormats( this.props ).datetime ) {
            update = this.getStateFromProps( nextProps );
        }
        if ( update.open === undefined ){
            if ( this.props.closeOnSelect && this.state.currentView !== 'time' ){
        if ( update.open === undefined ) {
            if ( this.props.closeOnSelect && this.state.currentView !== 'time' ) {
                update.open = false;
            }
            else {
                update.open = this.state.open;
            }
        }
        if ( nextProps.viewMode !== this.props.viewMode ) {
            update.currentView = nextProps.viewMode;
        }
        this.setState( update );
    },
example/viewModeChangeExample.js
New file
@@ -0,0 +1,34 @@
var DateTime = require('../DateTime.js');
var React = require('react');
var ReactDOM = require('react-dom');
var moment = require('moment');
var Wrapper = React.createClass({
    getInitialState: function() {
        return {
            viewMode: 'time'
        };
    },
    updateView: function(format) {
        console.log('changing viewMode to days');
        this.setState({
            viewMode: 'days'
        });
    },
    componentDidMount: function() {
        setTimeout(this.updateView, 3000);
    },
    render: function() {
        console.log('Current viewmode: ' + this.state.viewMode);
        return React.createElement(DateTime,
            { viewMode: this.state.viewMode, defaultValue: moment() });
    }
});
ReactDOM.render(
  React.createElement(Wrapper),
  document.getElementById('datetime')
);