Skip to content

Commit ca268cf

Browse files
Merge pull request #5948 from tejas-fullstack/fix/5939
Fix/5939 : The calendar doesn't display the startDate as first month
2 parents 877403c + 8283ac1 commit ca268cf

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
339339
) {
340340
this.setState({ monthSelectedIn: 0 });
341341
}
342+
if (this.props.selectsRange && this.state.monthSelectedIn !== 0) {
343+
this.setState({ monthSelectedIn: 0 });
344+
}
342345
if (prevProps.highlightDates !== this.props.highlightDates) {
343346
this.setState({
344347
highlightDates: getHighLightDaysMap(this.props.highlightDates),

src/test/datepicker_test.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,39 @@ describe("DatePicker", () => {
28432843
expect(instance!.state.monthSelectedIn).toEqual(0);
28442844
});
28452845

2846+
it("should set monthSelectedIn to 0 when selectsRange is true", () => {
2847+
let instance: DatePicker | null = null;
2848+
const { rerender } = render(
2849+
<DatePicker
2850+
ref={(node) => {
2851+
instance = node;
2852+
}}
2853+
monthsShown={2}
2854+
inline
2855+
/>,
2856+
);
2857+
expect(instance).toBeTruthy();
2858+
act(() => {
2859+
(
2860+
instance!.state as unknown as { monthSelectedIn: number }
2861+
).monthSelectedIn = 1;
2862+
});
2863+
expect(instance!.state.monthSelectedIn).toEqual(1);
2864+
2865+
rerender(
2866+
<DatePicker
2867+
ref={(node) => {
2868+
instance = node;
2869+
}}
2870+
monthsShown={2}
2871+
inline
2872+
selectsRange
2873+
/>,
2874+
);
2875+
2876+
expect(instance!.state.monthSelectedIn).toEqual(0);
2877+
});
2878+
28462879
it("should disable non-jumping if prop focusSelectedMonth is true", () => {
28472880
let instance: DatePicker | null = null;
28482881
const { container } = render(

0 commit comments

Comments
 (0)