Skip to content

Commit 72bd657

Browse files
Merge pull request #5618 from johannrp27/patch-1
fix: correct usage of customHeaderCount to keep arrows on any monthsShown prop
2 parents 32f68ac + 5f23baa commit 72bd657

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

docs-site/src/components/Example/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { forwardRef, useState } from "react";
1+
import React, { forwardRef, useMemo, useState } from "react";
22
import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live";
33
import DatePicker, {
44
registerLocale,
@@ -35,6 +35,7 @@ export default class CodeExampleComponent extends React.Component {
3535
scope={{
3636
// NB any globals added here should also be referenced in ../../examples/.eslintrc
3737
useState,
38+
useMemo,
3839
DatePicker,
3940
CalendarContainer,
4041
...DateFNS,

docs-site/src/examples/renderCustomHeaderTwoMonths.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { useState, useMemo } from "react";
2+
13
() => {
2-
const [selectedDate, setSelectedDate] = useState(new Date());
4+
const [startDate, setStartDate] = useState(new Date());
5+
const monthsShown = useMemo(() => 2, []);
36
return (
47
<DatePicker
58
renderCustomHeader={({
@@ -14,8 +17,10 @@
1417
className={
1518
"react-datepicker__navigation react-datepicker__navigation--previous"
1619
}
17-
style={customHeaderCount === 1 ? { visibility: "hidden" } : null}
1820
onClick={decreaseMonth}
21+
style={{
22+
visibility: customHeaderCount === 0 ? "visible" : "hidden",
23+
}}
1924
>
2025
<span
2126
className={
@@ -36,8 +41,11 @@
3641
className={
3742
"react-datepicker__navigation react-datepicker__navigation--next"
3843
}
39-
style={customHeaderCount === 0 ? { visibility: "hidden" } : null}
4044
onClick={increaseMonth}
45+
style={{
46+
visibility:
47+
customHeaderCount === monthsShown - 1 ? "visible" : "hidden",
48+
}}
4149
>
4250
<span
4351
className={
@@ -49,9 +57,9 @@
4957
</button>
5058
</div>
5159
)}
52-
selected={selectedDate}
53-
onChange={(date) => setSelectedDate(date)}
54-
monthsShown={2}
60+
selected={startDate}
61+
onChange={(date) => setStartDate(date)}
62+
monthsShown={monthsShown}
5563
/>
5664
);
5765
};

0 commit comments

Comments
 (0)