Skip to content

Commit

Permalink
Added support for "disableOnClickOutside" property.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis90 authored and simeg committed Feb 8, 2018
1 parent 44164f0 commit 704c18f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ var Datetime = createClass({
},

handleClickOutside: function() {
if ( this.props.input && this.state.open && !this.props.open ) {
if ( this.props.input && this.state.open && !this.props.open && !this.props.disableOnClickOutside ) {
this.setState({ open: false }, function() {
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
});
Expand Down
22 changes: 22 additions & 0 deletions test/tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,28 @@ describe('Datetime', () => {
expect(utils.isOpen(component)).toBeTruthy();
});

it('disableOnClickOutside=true', () => {
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
component = utils.createDatetime({ value: date, disableOnClickOutside: true });

expect(utils.isOpen(component)).toBeFalsy();
utils.openDatepicker(component);
expect(utils.isOpen(component)).toBeTruthy();
document.dispatchEvent(new Event('mousedown'));
expect(utils.isOpen(component)).toBeTruthy();
});

it('disableOnClickOutside=false', () => {
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
component = utils.createDatetime({ value: date, disableOnClickOutside: false });

expect(utils.isOpen(component)).toBeFalsy();
utils.openDatepicker(component);
expect(utils.isOpen(component)).toBeTruthy();
document.dispatchEvent(new Event('mousedown'));
expect(utils.isOpen(component)).toBeFalsy();
});

it('increase time', () => {
let i = 0;
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
Expand Down

0 comments on commit 704c18f

Please sign in to comment.