Skip to content

Commit c2f48e4

Browse files
committed
fix: timepicker not show up
feat: adjust focusing element on open datepicker and timepicker
1 parent 1fbf84b commit c2f48e4

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-flatpickr-plus",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Flatpickr is a lightweight and powerful datetime picker. Svelte Flatpickr Plus is a wrapper for Flatpickr with some extra features.",
55
"homepage": "https://github.com/kodaicoder/svelte-flatpickr-plus",
66
"bugs": {

src/lib/actions.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,35 @@ function attachFlatpickr(node, opts, plugins = opts.noCalendar ? [] : [new yearD
198198
const fp = flatpickr(node, {
199199
...opts,
200200
onOpen: [
201-
function (selectedDates, dateStr, instance) {
202-
instance.altInput.setAttribute('readonly', true);
201+
async function (selectedDates, dateStr, instance) {
202+
if (instance.altInput) {
203+
instance.altInput.setAttribute('readonly', true);
204+
205+
const dayElement = await instance.days;
206+
if (dayElement) {
207+
if (dayElement.querySelector('.today')) {
208+
dayElement.querySelector('.today').focus();
209+
} else {
210+
dayElement.querySelector('.selected').focus();
211+
}
212+
}
213+
} else {
214+
instance.input.setAttribute('readonly', true);
215+
instance.hourElement.focus()
216+
console.log();
217+
}
203218
},
204219
...opts.onOpen
205220
],
206221
onClose: [
207222
function (selectedDates, dateStr, instance) {
208-
instance.altInput.setAttribute('readonly', false);
209-
instance.altInput.blur();
223+
if (instance.altInput) {
224+
instance.altInput.setAttribute('readonly', false);
225+
instance.altInput.blur();
226+
} else {
227+
instance.input.setAttribute('readonly', false);
228+
instance.input.blur();
229+
}
210230
},
211231
...opts.onClose
212232
],

0 commit comments

Comments
 (0)