From 704c18fe9302dda68dfb8f18d85baea3739a2147 Mon Sep 17 00:00:00 2001 From: Dennis Alves <dennis.alves@live.com> Date: Thu, 08 Feb 2018 07:52:11 +0100 Subject: [PATCH] Added support for "disableOnClickOutside" property. --- test/tests.spec.js | 22 ++++++++++++++++++++++ DateTime.js | 2 +- 2 files changed, 23 insertions(+), 1 deletions(-) diff --git a/DateTime.js b/DateTime.js index 08dfc6d..1a7d6e6 100644 --- a/DateTime.js +++ b/DateTime.js @@ -347,7 +347,7 @@ }, 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 ); }); diff --git a/test/tests.spec.js b/test/tests.spec.js index 252e84f..3b5c8b5 100644 --- a/test/tests.spec.js +++ b/test/tests.spec.js @@ -522,6 +522,28 @@ 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), -- Gitblit v1.9.3