diff --git a/src/Calendar.jsx b/src/Calendar.jsx
index 4c7f5d74..f8f2c359 100644
--- a/src/Calendar.jsx
+++ b/src/Calendar.jsx
@@ -130,6 +130,9 @@ const getDetailValueArray = (value, minDate, maxDate, maxDetail) => {
const getActiveStartDate = (props) => {
const {
activeStartDate,
+ defaultActiveStartDate,
+ defaultValue,
+ defaultView,
maxDate,
maxDetail,
minDate,
@@ -138,10 +141,10 @@ const getActiveStartDate = (props) => {
view,
} = props;
- const rangeType = getView(view, minDetail, maxDetail);
+ const rangeType = getView(view || defaultView, minDetail, maxDetail);
const valueFrom = (
- activeStartDate,
- getDetailValueFrom(value, minDate, maxDate, maxDetail)
+ activeStartDate || defaultActiveStartDate
+ || getDetailValueFrom(value || defaultValue, minDate, maxDate, maxDetail)
|| new Date()
);
return getBegin(rangeType, valueFrom);
@@ -152,7 +155,7 @@ const isSingleValue = value => value && [].concat(value).length === 1;
export default class Calendar extends Component {
state = {
/* eslint-disable react/destructuring-assignment */
- activeStartDate: this.props.defaultActiveStartDate || getActiveStartDate(this.props),
+ activeStartDate: getActiveStartDate(this.props),
view: this.props.defaultView,
value: this.props.defaultValue,
/* eslint-enable react/destructuring-assignment */
diff --git a/src/Calendar.spec.jsx b/src/Calendar.spec.jsx
index b7db42be..8a026061 100644
--- a/src/Calendar.spec.jsx
+++ b/src/Calendar.spec.jsx
@@ -170,9 +170,22 @@ describe('Calendar', () => {
expect(monthView.prop('showNeighboringMonth')).toBeTruthy();
});
+ it('displays a view with a given value when defaultValue is given', () => {
+ const defaultValue = new Date(2017, 0, 15);
+ const component = shallow(
+ ,
+ );
+
+ const monthView = component.find('MonthView');
+
+ expect(monthView.prop('activeStartDate')).toEqual(new Date(2017, 0, 1));
+ });
+
it('displays a view with a given value when value is given', () => {
const value = new Date(2017, 0, 15);
- const component = mount(
+ const component = shallow(
,
@@ -183,9 +196,37 @@ describe('Calendar', () => {
expect(monthView.prop('activeStartDate')).toEqual(new Date(2017, 0, 1));
});
+ it('displays a view with defaultActiveStartDate when value is given and defaultActiveStartDate is given', () => {
+ const defaultActiveStartDate = new Date(2017, 0, 1);
+ const value = new Date(2018, 0, 15);
+ const component = shallow(
+ ,
+ );
+
+ const monthView = component.find('MonthView');
+
+ expect(monthView.prop('activeStartDate')).toEqual(defaultActiveStartDate);
+ });
+
+ it('displays a view with defaultActiveStartDate when no value is given and defaultActiveStartDate is given', () => {
+ const defaultActiveStartDate = new Date(2017, 0, 1);
+ const component = shallow(
+ ,
+ );
+
+ const monthView = component.find('MonthView');
+
+ expect(monthView.prop('activeStartDate')).toEqual(defaultActiveStartDate);
+ });
+
it('displays a view with activeStartDate when no value is given and activeStartDate is given', () => {
const activeStartDate = new Date(2017, 0, 1);
- const component = mount(
+ const component = shallow(
,
@@ -199,7 +240,7 @@ describe('Calendar', () => {
it('displays a view with today\'s date when no value and no activeStartDate is given', () => {
const today = new Date();
const beginOfCurrentMonth = getMonthStart(today);
- const component = mount(
+ const component = shallow(
,
);