Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-core/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const DatePickerBase = (
className,
locale = undefined,
dateFormat = yyyyMMddFormat,
dateParse = (val: string) => val.split('-').length === 3 && new Date(`${val}T00:00:00`),
dateParse = (val: string) => (val.split('-').length === 3 ? new Date(`${val}T00:00:00`) : new Date(undefined)),
Copy link
Contributor Author

@thatblindgeye thatblindgeye Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resolves the issue mentioned here #9721 (comment) regarding the return type of this prop. This basically just ensures that a Date type is always returned without really changing the outcome (instead of false we just get an invalid date object which should have the same effect).

Alternatively we could update the return type to include boolean (probably not the best since we're using dateParse to set internal date state) or update the default function to just return something like new Date(val.replace("/", "-")...), which would also satisfy a comment in the original issue of locales that use forward slashes for dates (or return an invalid date object).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should work fine - i'm approving as is. but i do think the point about forward slashes is valid, and if we don't add it as part of this, it probably makes sense to capture it in another issue.

isDisabled = false,
placeholder = 'YYYY-MM-DD',
value: valueProp = '',
Expand Down Expand Up @@ -230,7 +230,7 @@ const DatePickerBase = (
return (
<div className={css(styles.datePicker, className)} ref={datePickerWrapperRef} style={style} {...props}>
<Popover
elementToFocus={valueDate ? focusSelectorForSelectedDate : focusSelectorForUnselectedDate}
elementToFocus={isValidDate(valueDate) ? focusSelectorForSelectedDate : focusSelectorForUnselectedDate}
position="bottom"
bodyContent={
<CalendarMonth
Expand Down