fix: Date Range Picker behavior (#17914)
* fix: Date Range Picker behaviour * remove console log * update * update * update css --------- Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
1 parent
58b77b2a16
commit
0aa58c1095
4 files changed
+27
-26
No files matched your search
@@ -42,7 +42,8 @@ function Calendar({
|
||||
buttonClasses({ color: "minimal" }),
|
||||
"w-8 h-8 md:h-11 md:w-11 p-0 text-sm font-medium aria-selected:opacity-100 inline-flex items-center justify-center"
|
||||
),
|
||||
day_range_end: "day-range-end",
|
||||
day_range_end: "hover:!bg-inverted hover:!text-inverted",
|
||||
day_range_start: "hover:!bg-inverted hover:!text-inverted",
|
||||
day_selected: "bg-inverted text-inverted",
|
||||
day_today: "",
|
||||
day_outside: "",
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
import { format } from "date-fns";
|
||||
import * as React from "react";
|
||||
import type { DateRange } from "react-day-picker";
|
||||
|
||||
import { classNames as cn } from "@calcom/lib";
|
||||
|
||||
@@ -26,12 +25,13 @@ export function DatePickerWithRange({
|
||||
onDatesChange,
|
||||
disabled,
|
||||
}: React.HTMLAttributes<HTMLDivElement> & DatePickerWithRangeProps) {
|
||||
// Even though this is uncontrolled we need to do a bit of logic to improve the UX when selecting dates
|
||||
function _onDatesChange(onChangeValues: DateRange | undefined) {
|
||||
if (onChangeValues?.from && !onChangeValues?.to) {
|
||||
onDatesChange({ startDate: onChangeValues.from, endDate: onChangeValues.from });
|
||||
function handleDayClick(date: Date) {
|
||||
if (dates?.endDate) {
|
||||
onDatesChange({ startDate: date, endDate: undefined });
|
||||
} else {
|
||||
onDatesChange({ startDate: onChangeValues?.from, endDate: onChangeValues?.to });
|
||||
const startDate = date < dates.startDate ? date : dates.startDate;
|
||||
const endDate = date < dates.startDate ? dates.startDate : date;
|
||||
onDatesChange({ startDate, endDate });
|
||||
}
|
||||
}
|
||||
const fromDate = minDate ?? new Date();
|
||||
@@ -41,7 +41,7 @@ export function DatePickerWithRange({
|
||||
<Popover.Root>
|
||||
<Popover.Trigger asChild>
|
||||
<Button
|
||||
id="date"
|
||||
data-testid="date-range"
|
||||
color="secondary"
|
||||
EndIcon="calendar"
|
||||
className={cn("justify-between text-left font-normal", !dates && "text-subtle")}>
|
||||
@@ -51,7 +51,7 @@ export function DatePickerWithRange({
|
||||
{format(dates.startDate, "LLL dd, y")} - {format(dates.endDate, "LLL dd, y")}
|
||||
</>
|
||||
) : (
|
||||
format(dates.startDate, "LLL dd, y")
|
||||
<>{format(dates.startDate, "LLL dd, y")} - End</>
|
||||
)
|
||||
) : (
|
||||
<span>Pick a date</span>
|
||||
@@ -70,7 +70,7 @@ export function DatePickerWithRange({
|
||||
mode="range"
|
||||
defaultMonth={dates?.startDate}
|
||||
selected={{ from: dates?.startDate, to: dates?.endDate }}
|
||||
onSelect={(values) => _onDatesChange(values)}
|
||||
onDayClick={(day) => handleDayClick(day)}
|
||||
numberOfMonths={1}
|
||||
disabled={disabled}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user