Skip to content

adjustDayPickerHeight not calculating predictably when setting numberOfMonths prop dynamically #1394

@LMulvey

Description

@LMulvey

On our project, we're using a grid system that optionally passes us a screenClass prop to tell us what breakpoint we're currently in. We're using that breakpoint to pass a numberOfMonths prop to the DayPickerRangeController to render either two months for desktop or one month for mobile.

When we're doing this, our function initializes as sm, which initially passes numberOfMonths={1}. It's changed to numberOfMonths={2} shortly after once window.innerWidth is captured and the method is run.

Setting it to 1 on initial load breaks adjustDayPickerHeight for a month either 2 or 3 greater than the current one. As it's calculated based off of calendarMonthWeeks, which is only set on componentDidMount right now, that value becomes stale until it's triggered again.

adjustmonthheightissues

Possible Fix

Adding a check to componentDidUpdate for a variation in numberOfMonths and then triggering setCalendarMonthWeeks again fixes the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions