Skip to content

Commit

Permalink
fix: Range Calendar/Picker single day range selection (melt-ui#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored and lolcabanon committed Apr 20, 2024
1 parent 780ced0 commit b9d9ba3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-olives-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@melt-ui/svelte': patch
---

Range Calendar/Picker: fixed bug preventing a range with the same start and end date (Closes #898)
3 changes: 2 additions & 1 deletion src/lib/builders/date-range-field/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getDefaultDate,
getFirstSegment,
isBefore,
isBeforeOrSame,
} from '$lib/internal/helpers/date/index.js';
import {
addMeltEventListener,
Expand Down Expand Up @@ -154,7 +155,7 @@ export function createDateRangeField(props?: CreateDateRangeFieldProps) {
return false;
}

if (!isBefore($value?.start, $value?.end)) {
if (!isBeforeOrSame($value?.start, $value?.end)) {
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/builders/range-calendar/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,9 @@ export function createRangeCalendar<T extends DateValue = DateValue>(
}
}

if ($startValue && isSameDay($startValue, date) && !preventDeselect.get() && !$endValue) {
if ($startValue && $endValue && isSameDay($endValue, date) && !preventDeselect.get()) {
startValue.set(undefined);
endValue.set(undefined);
placeholder.set(date);
announcer.announce('Selected date is now empty.', 'polite');
return;
Expand Down

0 comments on commit b9d9ba3

Please sign in to comment.