-
Notifications
You must be signed in to change notification settings - Fork 16
feat: enhance DateRangePicker with clear and set range buttons #1237
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,15 +278,11 @@ const TimeSelector = forwardRef<HTMLDivElement, TimeSelectorProps>( | |
|
|
||
| const handleOpenChange = useCallback( | ||
| (open: boolean) => { | ||
| const isDateSelected = | ||
| isStart && selectedRange | ||
| ? selectedRange.startDate | ||
| : selectedRange?.endDate | ||
| if (!isProcessingSelection && isDateSelected) { | ||
| if (!isProcessingSelection) { | ||
| setIsOpen(open) | ||
| } | ||
| }, | ||
| [isProcessingSelection, selectedRange, isStart] | ||
| [isProcessingSelection] | ||
| ) | ||
|
|
||
| const handleInputChange = useCallback( | ||
|
|
@@ -402,9 +398,9 @@ const TimeSelector = forwardRef<HTMLDivElement, TimeSelectorProps>( | |
| id={id} | ||
| type="text" | ||
| disabled={ | ||
| isStart && selectedRange | ||
| ? !selectedRange.startDate | ||
| : !selectedRange?.endDate | ||
| isStart | ||
| ? false | ||
| : !!selectedRange && !selectedRange.endDate | ||
| } | ||
|
Comment on lines
398
to
404
|
||
| value={inputValue} | ||
| onChange={handleInputChange} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1829,7 +1829,7 @@ export const handleDateInputChange = ( | |
| value: string, | ||
| dateFormat: string, | ||
| currentRange: DateRange | undefined, | ||
| timeValue?: string, | ||
| _timeValue?: string, | ||
| isStartDate: boolean = true, | ||
| disableFutureDates: boolean = false, | ||
| disablePastDates: boolean = false, | ||
|
|
@@ -1852,8 +1852,11 @@ export const handleDateInputChange = ( | |
|
|
||
| if (validation.isValid && isDateInputComplete(formattedValue, dateFormat)) { | ||
| const today = getTodayInTimezone(timezone) | ||
| const [day, month, year] = '18/02/2026'.split('/') | ||
| const date = new Date(+year, +month - 1, +day) | ||
| const dateForCheck = parseDate(formattedValue, dateFormat, 12, 0) | ||
| const date = | ||
| dateForCheck && isValidDate(dateForCheck) | ||
| ? dateForCheck | ||
| : new Date() | ||
| const endDateTimeCheck = | ||
|
Comment on lines
+1855
to
1860
|
||
| disableFutureDates && today && isDateToday(date, today) | ||
| const startDateTimeCheck = | ||
|
|
@@ -1909,14 +1912,14 @@ export const handleDateInputChange = ( | |
| ] | ||
|
|
||
| const parsedDate = parseDate(formattedValue, dateFormat, hour, minute) | ||
| if (timeValue && parsedDate !== null && isValidDate(parsedDate)) { | ||
| if (parsedDate !== null && isValidDate(parsedDate)) { | ||
| updatedRange = isStartDate | ||
| ? currentRange | ||
| ? { ...currentRange, startDate: parsedDate } | ||
| : { startDate: parsedDate } | ||
| : currentRange | ||
| ? { ...currentRange, endDate: parsedDate } | ||
| : undefined | ||
| : { startDate: parsedDate, endDate: parsedDate } | ||
|
Comment on lines
1918
to
+1922
|
||
| } | ||
| } | ||
|
|
||
|
|
||
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.
The new
value === undefinedreset behavior is a regression-prone path (and fixes Issue #1187). There are existing DateRangePicker test suites; please add a regression test that renders withvalue={undefined}and asserts the trigger/input shows the placeholder and that today is not marked as selected by default.