immich/web/src/lib/components/elements/date-input.svelte
Michel Heusschen 4272b496ff
fix(web): prevent resetting date input when entering 0 (#7415)
* fix(web): prevent resetting date input when entering 0

* resolve conflict

---------

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2024-02-26 21:07:49 -06:00

25 lines
550 B
Svelte

<script lang="ts">
import type { HTMLInputAttributes } from 'svelte/elements';
interface $$Props extends HTMLInputAttributes {
type: 'date' | 'datetime-local';
}
export let value: $$Props['value'] = undefined;
$: updatedValue = value;
</script>
<input
{...$$restProps}
{value}
on:input={(e) => {
updatedValue = e.currentTarget.value;
// Only update when value is not empty to prevent resetting the input
if (updatedValue !== '') {
value = updatedValue;
}
}}
on:blur={() => (value = updatedValue)}
/>