+ {month.map((m, j) => (
+
{
+ this.onMonthClick(ev.target, m);
+ }}
+ className={classnames(
+ "react-datepicker__month-text",
+ `react-datepicker__month-${m}`
+ )}
+ >
+ {utils.getMonthShortInLocale(m, this.props.locale)}
+
+ ))}
+
+ ));
+ };
+
getClassNames = () => {
- const { selectingDate, selectsStart, selectsEnd } = this.props;
- return classnames("react-datepicker__month", {
- "react-datepicker__month--selecting-range":
- selectingDate && (selectsStart || selectsEnd)
- });
+ const {
+ selectingDate,
+ selectsStart,
+ selectsEnd,
+ showMonthYearPicker
+ } = this.props;
+ return classnames(
+ "react-datepicker__month",
+ {
+ "react-datepicker__month--selecting-range":
+ selectingDate && (selectsStart || selectsEnd)
+ },
+ { "react-datepicker__monthPicker": showMonthYearPicker }
+ );
};
render() {
+ const { showMonthYearPicker } = this.props;
return (
- {this.renderWeeks()}
+ {showMonthYearPicker ? this.renderMonths() : this.renderWeeks()}
);
}
diff --git a/src/stylesheets/datepicker.scss b/src/stylesheets/datepicker.scss
index d272ef244..604e629b5 100644
--- a/src/stylesheets/datepicker.scss
+++ b/src/stylesheets/datepicker.scss
@@ -104,7 +104,8 @@
}
.react-datepicker__current-month,
-.react-datepicker-time__header {
+.react-datepicker-time__header,
+.react-datepicker-year-header {
margin-top: 0;
color: $datepicker__header-color;
font-weight: bold;
@@ -200,6 +201,10 @@
.react-datepicker__month {
margin: $datepicker__margin;
text-align: center;
+ .react-datepicker__month-text {
+ display: inline-block;
+ width: 4rem;
+ }
}
.react-datepicker__input-time-container {
@@ -329,7 +334,8 @@
margin: $datepicker__day-margin;
}
-.react-datepicker__day {
+.react-datepicker__day,
+.react-datepicker__month-text {
cursor: pointer;
&:hover {
diff --git a/test/calendar_test.js b/test/calendar_test.js
index 410b7973c..969a99c3e 100644
--- a/test/calendar_test.js
+++ b/test/calendar_test.js
@@ -1025,4 +1025,52 @@ describe("Calendar", function() {
expect(timeInputClassname).to.have.length(1);
});
});
+
+ describe("when showMonthYearPicker is enabled", () => {
+ let calendar = mount(
+