Skip to content

Commit f6db982

Browse files
committed
fix(@clayui/date-picker): Adjusts the behaviour of date range when clicking on the dot button
Basically if there is a selected date and it is previous to the start date, then the end date is set with the current day. As discussed here: #4008 (comment)
1 parent a64ba5e commit f6db982

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/clay-date-picker/src/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,17 @@ const ClayDatePicker: React.FunctionComponent<IProps> = React.forwardRef<
408408

409409
changeMonth(NEW_DATE);
410410

411-
setDaysSelected([NEW_DATE, endDate]);
411+
const newDaysSelected: [Date, Date] =
412+
range && endDate < NEW_DATE
413+
? [endDate, NEW_DATE]
414+
: [NEW_DATE, endDate];
415+
416+
setDaysSelected(newDaysSelected);
412417

413418
let dateFormatted;
414419

415420
if (range) {
416-
dateFormatted = fromRangeToString(
417-
[NEW_DATE, endDate],
418-
dateFormat
419-
);
421+
dateFormatted = fromRangeToString(newDaysSelected, dateFormat);
420422
} else if (time) {
421423
dateFormatted = formatDate(
422424
parseDate(currentTime, TIME_FORMAT, NEW_DATE),

0 commit comments

Comments
 (0)