Skip to content

Commit d0b63bc

Browse files
committed
Fix calendar not toggling when open prop changes
1 parent c1a952d commit d0b63bc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

DateTime.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ var Datetime = createClass({
152152
}
153153

154154
if ( updatedState.open === undefined ) {
155-
if ( this.props.closeOnSelect && this.state.currentView !== 'time' ) {
155+
if ( typeof nextProps.open !== 'undefined' ) {
156+
updatedState.open = nextProps.open;
157+
} else if ( this.props.closeOnSelect && this.state.currentView !== 'time' ) {
156158
updatedState.open = false;
157159
} else {
158160
updatedState.open = this.state.open;

test/tests.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ describe('Datetime', () => {
9797
expect(utils.isYearView(component)).toBeTruthy();
9898
});
9999

100+
it('toggles calendar when open prop changes', () => {
101+
const component = utils.createDatetime({ open: false });
102+
expect(utils.isOpen(component)).toBeFalsy();
103+
// expect(component.find('.rdtOpen').length).toEqual(0);
104+
component.setProps({ open: true });
105+
expect(utils.isOpen(component)).toBeTruthy();
106+
// expect(component.find('.rdtOpen').length).toEqual(1);
107+
component.setProps({ open: false });
108+
expect(utils.isOpen(component)).toBeFalsy();
109+
// expect(component.find('.rdtOpen').length).toEqual(0);
110+
});
111+
100112
it('selectYear', () => {
101113
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
102114
component = utils.createDatetime({ viewMode: 'years', defaultValue: date });

0 commit comments

Comments
 (0)