flowbite-svelte 1.10.9 → 1.10.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -120,10 +120,34 @@
|
|
|
120
120
|
|
|
121
121
|
function handleInputChangeWithDateFns() {
|
|
122
122
|
const inputValue = inputElement?.value?.trim();
|
|
123
|
-
if (!inputValue)
|
|
123
|
+
if (!inputValue) {
|
|
124
|
+
rangeFrom = undefined;
|
|
125
|
+
rangeTo = undefined;
|
|
126
|
+
inputElement?.setCustomValidity("");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
124
129
|
|
|
125
130
|
inputElement?.setCustomValidity("");
|
|
126
131
|
|
|
132
|
+
if (range) {
|
|
133
|
+
const parts = inputValue.split(" - "); // Split the string by " - "
|
|
134
|
+
if (parts.length === 2) {
|
|
135
|
+
const parsedFrom = tryParseDate(parts[0]);
|
|
136
|
+
const parsedTo = tryParseDate(parts[1]);
|
|
137
|
+
|
|
138
|
+
if (parsedFrom && isValid(parsedFrom) && isDateAvailable(parsedFrom) && parsedTo && isValid(parsedTo) && isDateAvailable(parsedTo)) {
|
|
139
|
+
rangeFrom = parsedFrom;
|
|
140
|
+
rangeTo = parsedTo;
|
|
141
|
+
onselect?.({ from: rangeFrom, to: rangeTo });
|
|
142
|
+
return; // Successfully parsed range
|
|
143
|
+
} else {
|
|
144
|
+
inputElement?.setCustomValidity(`Please enter date range in format: ${getDateFormatPattern()} - ${getDateFormatPattern()}`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Original single date parsing logic
|
|
127
151
|
const parsedDate = tryParseDate(inputValue);
|
|
128
152
|
|
|
129
153
|
if (!parsedDate || !isValid(parsedDate)) {
|
|
@@ -277,7 +301,16 @@
|
|
|
277
301
|
focusedDate = addDay(focusedDate, 7);
|
|
278
302
|
break;
|
|
279
303
|
case "Enter":
|
|
280
|
-
|
|
304
|
+
if (range) {
|
|
305
|
+
if (rangeFrom && rangeTo) {
|
|
306
|
+
if (autohide && !inline) isOpen = false;
|
|
307
|
+
} else {
|
|
308
|
+
handleDaySelect(focusedDate);
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
handleDaySelect(focusedDate);
|
|
312
|
+
if (autohide && !inline) isOpen = false;
|
|
313
|
+
}
|
|
281
314
|
break;
|
|
282
315
|
case "Escape":
|
|
283
316
|
isOpen = false;
|
|
@@ -301,7 +334,14 @@
|
|
|
301
334
|
}
|
|
302
335
|
|
|
303
336
|
function handleInputKeydown(event: KeyboardEvent) {
|
|
304
|
-
if (event.key === "Enter"
|
|
337
|
+
if (event.key === "Enter") {
|
|
338
|
+
event.preventDefault(); // Prevent default form submission or other Enter key behaviors
|
|
339
|
+
handleInputChangeWithDateFns(); // Call the function to parse and apply the date
|
|
340
|
+
if (autohide && !inline) {
|
|
341
|
+
// Optionally close the datepicker after applying
|
|
342
|
+
isOpen = false;
|
|
343
|
+
}
|
|
344
|
+
} else if (event.key === " ") {
|
|
305
345
|
event.preventDefault();
|
|
306
346
|
isOpen = !isOpen;
|
|
307
347
|
}
|