-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Rework DayPicker
api
#4783
[core] Rework DayPicker
api
#4783
Conversation
@@ -49,11 +45,12 @@ export interface ExportedDayPickerProps<TDate> | |||
renderLoading?: () => React.ReactNode; | |||
} | |||
|
|||
export interface DayPickerProps<TDate, TValue> extends ExportedDayPickerProps<TDate> { | |||
export interface DayPickerProps<TDate> extends ExportedDayPickerProps<TDate> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer rely on TValue
, the component does not care what is the format, it always takes (TDate | null)[]
as an input.
@@ -140,25 +137,15 @@ export function DayPicker<TDate, TValue>(props: DayPickerProps<TDate, TValue>) { | |||
return; | |||
} | |||
|
|||
// TODO possibly buggy line figure out and add tests | |||
let finalDate: TDate; | |||
if (date && !Array.isArray(date)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check has moved in CalendarPicker
where we now that it is not a range
This is fixing #4703 because we no longer do the bugger Array.isArray
check.
.filter(Boolean) | ||
.map((selectedDateItem) => selectedDateItem && utils.startOfDay(selectedDateItem)); | ||
const validSelectedDays = selectedDays | ||
.filter((day): day is TDate => !!day) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.filter(Boolean)
was not inferring the type so selectedDates
still had the type (TDate | null)[]
(which is why we were doing a useless boolean check below for the selected
prop of renderDay
@@ -141,4 +141,38 @@ describe('<CalendarPicker />', () => { | |||
|
|||
expect(screen.getByText('2019/01')).toBeVisible(); | |||
}); | |||
|
|||
it('should set time to be midnight when selecting a date without a previous date', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste of the tests of DayPicker
since the tested logic now lives in CalendarPicker
I just changed the props to have the correct view and month rendered.
These are the results for the performance tests:
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
I checked it and it looks good. I also took the time to run it locally. |
Follow up on #4736 with a small potential bug fix.
DayPicker
and rename isselectedDays
instead ofdate
onChange
intoonSelectedDayChange
since it's not a callback of thevalue
prop (we only pass the modified date and let the upper component decide how it impacts the list of selected days)What's next
DayPicker
component independently of the context