Skip to content

Commit

Permalink
fix(@clayui/date-picker): Adjusts the behaviour of date range when cl…
Browse files Browse the repository at this point in the history
…icking 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)
  • Loading branch information
diegonvs committed Apr 14, 2021
1 parent a64ba5e commit f6db982
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/clay-date-picker/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,17 @@ const ClayDatePicker: React.FunctionComponent<IProps> = React.forwardRef<

changeMonth(NEW_DATE);

setDaysSelected([NEW_DATE, endDate]);
const newDaysSelected: [Date, Date] =
range && endDate < NEW_DATE
? [endDate, NEW_DATE]
: [NEW_DATE, endDate];

setDaysSelected(newDaysSelected);

let dateFormatted;

if (range) {
dateFormatted = fromRangeToString(
[NEW_DATE, endDate],
dateFormat
);
dateFormatted = fromRangeToString(newDaysSelected, dateFormat);
} else if (time) {
dateFormatted = formatDate(
parseDate(currentTime, TIME_FORMAT, NEW_DATE),
Expand Down

0 comments on commit f6db982

Please sign in to comment.