Skip to content

selected value handling in react-date-picker causes getMonth() errors #9

@delmac-dev

Description

@delmac-dev

Bug: selected value handling in react-date-picker causes getMonth() errors

Description:

When using react-date-picker in modes like range or multiple, selecting a month by tapping on the month caption causes an error. This happens because the selected value can be a string, an object (from and to in range mode), or an array (multiple dates). Directly treating selected as a Date leads to errors when trying to call getMonth().

Steps to Reproduce:

  1. Use react-date-picker in range or multiple mode.
  2. Tap on the month caption to select a month.
  3. Select any month.
  4. The error TypeError: selected.getMonth is not a function occurs.

Expected Behavior:

getMonth() should only be called on valid Date objects, with proper checks for selected being a string, object, or array.

Actual Behavior:

TypeError: selected.getMonth is not a function occurs when selected is not a Date.

Suggested Solution:

Implement proper type-checking for the selected value based on its type (string, object, array) before attempting to call getMonth().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions