You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Use react-date-picker in range or multiple mode.
Tap on the month caption to select a month.
Select any month.
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().
The text was updated successfully, but these errors were encountered:
setNavView("days");if(mode==="range"){constselectedRange=selectedasunknownas{from: Date;to: Date};// if mode is range, use `selectedRange.from`goToMonth(newDate(displayYears.from+i,selectedRange.from?.getMonth()??newDate().getMonth()));return;}goToMonth(newDate(displayYears.from+i,(selectedasDate|undefined)?.getMonth()??0));
Bug:
selected
value handling inreact-date-picker
causesgetMonth()
errorsDescription:
When using
react-date-picker
in modes likerange
ormultiple
, selecting a month by tapping on the month caption causes an error. This happens because theselected
value can be a string, an object (from
andto
in range mode), or an array (multiple dates). Directly treatingselected
as aDate
leads to errors when trying to callgetMonth()
.Steps to Reproduce:
react-date-picker
inrange
ormultiple
mode.TypeError: selected.getMonth is not a function
occurs.Expected Behavior:
getMonth()
should only be called on validDate
objects, with proper checks forselected
being a string, object, or array.Actual Behavior:
TypeError: selected.getMonth is not a function
occurs whenselected
is not aDate
.Suggested Solution:
Implement proper type-checking for the
selected
value based on its type (string
,object
,array
) before attempting to callgetMonth()
.The text was updated successfully, but these errors were encountered: