Skip to content

Commit

Permalink
fix: allow editing of current date when opening date picker
Browse files Browse the repository at this point in the history
  • Loading branch information
cpulvermacher committed Feb 13, 2025
1 parent 62c1e56 commit 42fde1c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/popup/Datepicker.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { DatePicker } from '@svelte-plugins/datepicker'
import { tick } from 'svelte'
import { overwriteYYYYMMDD } from '../util/common'
import { formatLocalTime, overwriteYYYYMMDD } from '../util/common'
interface Props {
fakeDate: string
Expand All @@ -26,6 +26,16 @@
async function toggleDatePicker() {
isOpen = !isOpen
if (isOpen) {
// when opening the date picker, allow editing the current date entered
let inputDateTimestamp = new Date(fakeDate).getTime()
if (isNaN(inputDateTimestamp)) {
// if date in input field is invalid, reset
const newDate = new Date()
fakeDate = formatLocalTime(newDate)
inputDateTimestamp = newDate.getTime()
}
pickerDate = inputDateTimestamp
inputRef.focus()
await tick() // wait for next DOM update
inputRef.setSelectionRange(0, 10)
Expand Down

0 comments on commit 42fde1c

Please sign in to comment.