Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
8.12k stars 2.24k forks source link

Months with 6 lines cause the calendar to shift if more than 2 months shown #5204

Closed incognos closed 1 week ago

incognos commented 3 weeks ago

Describe the bug Months with 6 lines cause the calendar to shift if more than 2 months shown

To Reproduce

over the summer of 2024, june starts on a saturday and ends on a sunday. This causes the month to have 6 lines.

<DatePicker
  swapRange
  selected={fieldStartDate.value}
  onChange={(dates: [Date | null, Date | null]) => {
    const [startDate, endDate] = dates
    setFieldValue('reportStartDate', startDate)
    setFieldTouched('reportStartDate', true)
    setFieldValue('reportEndDate', endDate)
    setFieldTouched('reportEndDate', true)
  }}
  maxDate={new Date()}
  startDate={fieldStartDate.value}
  endDate={fieldEndDate.value}
  monthsShown={4}
  selectsRange
  inline
  showDisabledMonthNavigation
/>

Expected behavior I don;t expect september to be completely out of alignment with the other months

Screenshots CleanShot 2024-11-01 at 17 33 12@2x

Desktop (please complete the following information):

pmacmillan commented 2 weeks ago

not sure if this is a good way to address this, but here is a workaround:

.react-datepicker {
  display: flex;
  flex-wrap: wrap;
}

or combine with calendarClassName if you're wary of overriding the main class.

i.e.

   <DatePicker ... calendarClassName="react-datepicker-flexible" ... />
.react-datepicker-flexible {
  display: flex;
  flex-wrap: wrap;
}

image

incognos commented 1 week ago

Did not fix it but appreciate the response. Limited to 2 months for now.