Skip to content

Commit

Permalink
fix: make isSelected reactive in datepicker (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chizaruu authored Oct 27, 2024
1 parent a88db49 commit 153a9c9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/datepicker/Datepicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,17 @@
return date.toLocaleDateString(locale, dateFormat);
}
function isSelected(day: Date): boolean {
function isSameDate(date1: Date | null, date2: Date | null): boolean {
if (!date1 || !date2) return false;
return date1.toDateString() === date2.toDateString();
}
$: isSelected = (day: Date): boolean => {
if (range) {
return !!(rangeFrom && day.toDateString() === rangeFrom.toDateString()) || !!(rangeTo && day.toDateString() === rangeTo.toDateString());
return isSameDate(day, rangeFrom) || isSameDate(day, rangeTo);
}
return !!(value && day.toDateString() === value.toDateString());
}
return isSameDate(day, value);
};
function isInRange(day: Date): boolean {
if (!range || !rangeFrom || !rangeTo) return false;
Expand Down

0 comments on commit 153a9c9

Please sign in to comment.