Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/lib/TimePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
browseDate.setMilliseconds(value)
}

browseDate = setTime(browseDate)
setText(browseDate)
}

Expand Down Expand Up @@ -134,6 +133,19 @@
function focus(e: FocusEvent & SpanEvent) {
select(e.currentTarget)
}

function focusout(e: FocusEvent) {
const node = e.currentTarget as HTMLElement
// Use setTimeout with 0ms delay to check focus after the browser has processed the current event cycle
// This is necessary because when switching focus between elements, the document.activeElement updates
// after the focusout event fires
setTimeout(() => {
if (!node.contains(document.activeElement)) {
browseDate = setTime(browseDate)
setText(browseDate)
}
}, 0)
}
</script>

{#if timePrecision}
Expand All @@ -146,6 +158,7 @@
e.preventDefault() // prevent text dragging
}
}}
on:focusout={focusout}
>
<span
bind:this={fields[0]}
Expand Down