Skip to content

Commit a05a63f

Browse files
authored
Merge pull request react-dates#620 from erin-doyle/missing_keepOpenOnDateSelect_prop
Added missing keepOpenOnDateSelect prop
2 parents d091b08 + 164eca8 commit a05a63f

File tree

2 files changed

+56
-21
lines changed

2 files changed

+56
-21
lines changed

src/components/SingleDatePicker.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export default class SingleDatePicker extends React.Component {
309309
navNext,
310310
withPortal,
311311
withFullScreenPortal,
312+
keepOpenOnDateSelect,
312313
initialVisibleMonth,
313314
renderMonth,
314315
renderDay,
@@ -344,6 +345,7 @@ export default class SingleDatePicker extends React.Component {
344345
monthFormat={monthFormat}
345346
withPortal={withPortal || withFullScreenPortal}
346347
focused={focused}
348+
keepOpenOnDateSelect={keepOpenOnDateSelect}
347349
hideKeyboardShortcutsPanel={hideKeyboardShortcutsPanel}
348350
initialVisibleMonth={initialVisibleMonth}
349351
navPrev={navPrev}

test/components/DayPickerSingleDateController_spec.jsx

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -500,29 +500,62 @@ describe('DayPickerSingleDateController', () => {
500500
expect(onDateChangeStub.callCount).to.equal(1);
501501
});
502502

503-
it('props.onFocusChange is called', () => {
504-
const onFocusChangeStub = sinon.stub();
505-
const wrapper = shallow(
506-
<DayPickerSingleDateController
507-
onDateChange={() => {}}
508-
onFocusChange={onFocusChangeStub}
509-
/>,
510-
);
511-
wrapper.instance().onDayClick(moment());
512-
expect(onFocusChangeStub.callCount).to.equal(1);
503+
describe('props.keepOpenOnDateSelect is false', () => {
504+
it('props.onFocusChange is called', () => {
505+
const onFocusChangeStub = sinon.stub();
506+
const wrapper = shallow(
507+
<DayPickerSingleDateController
508+
onDateChange={() => {}}
509+
onFocusChange={onFocusChangeStub}
510+
keepOpenOnDateSelect={false}
511+
/>,
512+
);
513+
wrapper.instance().onDayClick(moment());
514+
expect(onFocusChangeStub.callCount).to.equal(1);
515+
});
516+
517+
it('props.onClose is called', () => {
518+
const onCloseStub = sinon.stub();
519+
const wrapper = shallow(
520+
<DayPickerSingleDateController
521+
onDateChange={() => {}}
522+
onFocusChange={() => {}}
523+
onClose={onCloseStub}
524+
keepOpenOnDateSelect={false}
525+
/>,
526+
);
527+
wrapper.instance().onDayClick(moment());
528+
expect(onCloseStub.callCount).to.equal(1);
529+
});
513530
});
514531

515-
it('props.onClose is called', () => {
516-
const onCloseStub = sinon.stub();
517-
const wrapper = shallow(
518-
<DayPickerSingleDateController
519-
onDateChange={() => {}}
520-
onFocusChange={() => {}}
521-
onClose={onCloseStub}
522-
/>,
523-
);
524-
wrapper.instance().onDayClick(moment());
525-
expect(onCloseStub.callCount).to.equal(1);
532+
describe('props.keepOpenOnDateSelect is true', () => {
533+
it('props.onFocusChange is not called', () => {
534+
const onFocusChangeStub = sinon.stub();
535+
const wrapper = shallow(
536+
<DayPickerSingleDateController
537+
onDateChange={() => {}}
538+
onFocusChange={onFocusChangeStub}
539+
keepOpenOnDateSelect
540+
/>,
541+
);
542+
wrapper.instance().onDayClick(moment());
543+
expect(onFocusChangeStub.callCount).to.equal(0);
544+
});
545+
546+
it('props.onClose is not called', () => {
547+
const onCloseStub = sinon.stub();
548+
const wrapper = shallow(
549+
<DayPickerSingleDateController
550+
onDateChange={() => {}}
551+
onFocusChange={() => {}}
552+
onClose={onCloseStub}
553+
keepOpenOnDateSelect
554+
/>,
555+
);
556+
wrapper.instance().onDayClick(moment());
557+
expect(onCloseStub.callCount).to.equal(0);
558+
});
526559
});
527560
});
528561
});

0 commit comments

Comments
 (0)