Skip to content

Commit c86b222

Browse files
Merge pull request #3709 from DanielSharp01/master
fix(months): monthClassName is passed the month instead of the current day
2 parents 60d95bb + aa2394b commit c86b222

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

docs-site/src/examples/excludeDatesMonthPicker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
selected={startDate}
66
onChange={(date) => setStartDate(date)}
77
dateFormat="MM/yyyy"
8-
excludeDates={[1661990400000, 1664582400000, 1667260800000, 1672531200000]}
8+
excludeDates={[
9+
1661990400000, 1664582400000, 1667260800000, 1672531200000,
10+
]}
911
showMonthYearPicker
1012
/>
1113
);
12-
};
14+
};

docs-site/src/examples/includeDatesMonthPicker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
selected={startDate}
66
onChange={(date) => setStartDate(date)}
77
dateFormat="MM/yyyy"
8-
includeDates={[1661990400000, 1664582400000, 1667260800000, 1672531200000]}
8+
includeDates={[
9+
1661990400000, 1664582400000, 1667260800000, 1672531200000,
10+
]}
911
showMonthYearPicker
1012
/>
1113
);
12-
};
14+
};

src/month.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ export default class Month extends React.Component {
339339
excludeDates,
340340
includeDates,
341341
} = this.props;
342-
const _monthClassName = monthClassName ? monthClassName(day) : undefined;
342+
const _monthClassName = monthClassName
343+
? monthClassName(utils.setMonth(day, m))
344+
: undefined;
343345
const labelDate = utils.setMonth(day, m);
344346
return classnames(
345347
"react-datepicker__month-text",
@@ -355,7 +357,8 @@ export default class Month extends React.Component {
355357
selected
356358
),
357359
"react-datepicker__month-text--keyboard-selected":
358-
!this.props.disabledKeyboardNavigation && utils.getMonth(preSelection) === m,
360+
!this.props.disabledKeyboardNavigation &&
361+
utils.getMonth(preSelection) === m,
359362
"react-datepicker__month--in-range": utils.isMonthinRange(
360363
startDate,
361364
endDate,

test/datepicker_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ describe("DatePicker", () => {
19841984
expect(utils.getMinutes(date)).to.equal(22);
19851985
});
19861986
});
1987-
1987+
19881988
it("should selected month when specified minDate same month", () => {
19891989
const selected = utils.newDate("2023-01-09");
19901990
let date = null;

test/month_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ describe("Month", () => {
935935

936936
describe("if keyboard navigation is disabled", () => {
937937
const renderMonth = (props) =>
938-
mount(<Month showMonthYearPicker {...props} />);
938+
mount(<Month showMonthYearPicker {...props} />);
939939

940940
it("should not have the selected class", () => {
941941
let preSelected = utils.newDate("2015-08-01");
@@ -952,9 +952,9 @@ describe("Month", () => {
952952
});
953953

954954
expect(
955-
monthComponent
956-
.find(".react-datepicker__month--selected")
957-
.hasClass("react-datepicker__month-text--keyboard-selected")
955+
monthComponent
956+
.find(".react-datepicker__month--selected")
957+
.hasClass("react-datepicker__month-text--keyboard-selected")
958958
).to.equal(false);
959959
});
960960
});

0 commit comments

Comments
 (0)