marquex
2016-07-19 9012e8199a9db78b4a9d381378cf9843ec8c1a1e
Adds the closeOnTab prop.
2 files modified
38 ■■■■■ changed files
DateTime.js 16 ●●●● patch | view | raw | blame | history
tests/datetime-spec.js 22 ●●●●● patch | view | raw | blame | history
DateTime.js
@@ -23,7 +23,6 @@
    propTypes: {
        // value: TYPES.object | TYPES.string,
        // defaultValue: TYPES.object | TYPES.string,
        closeOnSelect: TYPES.bool,
        onFocus: TYPES.func,
        onBlur: TYPES.func,
        onChange: TYPES.func,
@@ -35,7 +34,9 @@
        viewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),
        isValidDate: TYPES.func,
        open: TYPES.bool,
        strictParsing: TYPES.bool
        strictParsing: TYPES.bool,
        closeOnSelect: TYPES.bool,
        closeOnTab: TYPES.bool
    },
    getDefaultProps: function() {
@@ -50,7 +51,9 @@
            onChange: nof,
            timeFormat: true,
            dateFormat: true,
            strictParsing: true
            strictParsing: true,
            closeOnSelect: false,
            closeOnTab: true
        };
    },
@@ -178,6 +181,12 @@
        return this.setState( update, function() {
            return this.props.onChange( localMoment.isValid() ? localMoment : this.state.inputValue );
        });
    },
    onInputKey: function( e ){
        if( e.which === 9 && this.props.closeOnTab ){
            this.closeCalendar();
        }
    },
    showView: function( view ){
@@ -363,6 +372,7 @@
                className: 'form-control',
                onFocus: this.openCalendar,
                onChange: this.onInputChange,
                onKeyDown: this.onInputKey,
                value: this.state.inputValue
            }, this.props.inputProps ))];
        } else {
tests/datetime-spec.js
@@ -477,6 +477,28 @@
        trigger( 'click', document.body );
    });
    it( 'closeOnTab:true', function(){
        createDatetime({ value: date });
        assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 );
        ev.focus( dt.input() );
        assert.notEqual( dt.dt().className.indexOf( 'rdtOpen' ), -1 );
        TestUtils.Simulate.keyDown(dt.input(), {key: "Tab", keyCode: 9, which: 9});
        assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 );
        trigger( 'click', document.body );
    });
    it( 'closeOnTab:false', function(){
        createDatetime({ value: date, closeOnTab: false });
        assert.equal( dt.dt().className.indexOf( 'rdtOpen' ), -1 );
        ev.focus( dt.input() );
        assert.notEqual( dt.dt().className.indexOf( 'rdtOpen' ), -1 );
        TestUtils.Simulate.keyDown(dt.input(), {key: "Tab", keyCode: 9, which: 9});
        assert.notEqual( dt.dt().className.indexOf( 'rdtOpen' ), -1 );
        trigger( 'click', document.body );
    });
    it( 'increase time', function( done ){
        var i = 0;
        createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){