From 9e289c33be4668aa9650954dda9e3a5757386104 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Sun, 8 Nov 2026 14:03:48 +0100 Subject: [PATCH] rework time component --- .../lib/components/toolbar/tools/Time.svelte | 2 + .../ui/time-picker/TimeComponentInput.svelte | 95 +++---- .../ui/time-picker/TimePicker.svelte | 262 +++++++++--------- 3 files changed, 170 insertions(+), 189 deletions(-) diff --git a/website/src/lib/components/toolbar/tools/Time.svelte b/website/src/lib/components/toolbar/tools/Time.svelte index a3ecb91e4..14bedc5ff 100644 --- a/website/src/lib/components/toolbar/tools/Time.svelte +++ b/website/src/lib/components/toolbar/tools/Time.svelte @@ -218,6 +218,7 @@ {:else} { diff --git a/website/src/lib/components/ui/time-picker/TimeComponentInput.svelte b/website/src/lib/components/ui/time-picker/TimeComponentInput.svelte index 7da363e20..2fb383e7a 100644 --- a/website/src/lib/components/ui/time-picker/TimeComponentInput.svelte +++ b/website/src/lib/components/ui/time-picker/TimeComponentInput.svelte @@ -1,63 +1,40 @@ - -
- + import { cn, type WithElementRef } from '$lib/utils.js'; + import type { HTMLInputAttributes } from 'svelte/elements'; + + let { + ref = $bindable(null), + value, + class: className, + ...restProps + }: WithElementRef> & { value: string } = $props(); + + // The padding of the fields of a native time input, which is larger in Firefox. + const padding = 'px-px [@supports(-moz-appearance:none)]:px-[3px]'; + + + + + + { - let input = document.activeElement; - if (input instanceof HTMLInputElement) { - input.select(); - } - onfocusin(e); - }} - class="w-[22px] {className ?? ''}" + inputmode="numeric" + autocomplete="off" + value={value || EMPTY_FIELD} + class={cn( + 'absolute inset-0 w-full bg-transparent text-center outline-none', + padding, + className + )} + onfocus={(e) => e.currentTarget.select()} + {...restProps} /> -
- - + diff --git a/website/src/lib/components/ui/time-picker/TimePicker.svelte b/website/src/lib/components/ui/time-picker/TimePicker.svelte index d192e9d2e..a291d3125 100644 --- a/website/src/lib/components/ui/time-picker/TimePicker.svelte +++ b/website/src/lib/components/ui/time-picker/TimePicker.svelte @@ -1,174 +1,176 @@ +
{ + digitsTyped = 0; + }} + onfocusout={handleFocusOut} > {#if showHours} { - if (typeof hours === 'string') { - hours = parseInt(hours); - } - if (hours < 0) { - hours = 0; - } - onChange(); - }} - onkeypress={onKeyPress} - onfocusin={() => { - countKeyPress = 0; - }} + oninput={(e) => + handleInput(e, normalizeUnbounded, (field) => (hours = field), minutesInput)} /> - : + : {/if} { - if (typeof minutes === 'string') { - minutes = parseInt(minutes); - } - if (showHours && minutes > 59) { - minutes = 59; - } else if (minutes < 0) { - minutes = 0; - } - minutes = minutes.toString().padStart(showHours ? 2 : 1, '0'); - onChange(); - }} - onkeypress={onKeyPress} - onfocusin={() => { - countKeyPress = 0; - }} + oninput={(e) => + handleInput( + e, + showHours ? normalizeSexagesimal : normalizeUnbounded, + (field) => (minutes = field), + secondsInput + )} /> - : + : { - if (typeof seconds === 'string') { - seconds = parseInt(seconds); - } - if (seconds > 59) { - seconds = 59; - } else if (seconds < 0) { - seconds = 0; - } - seconds = seconds.toString().padStart(2, '0'); - onChange(); - }} - onkeypress={onKeyPress} - onfocusin={() => { - countKeyPress = 0; - }} + oninput={(e) => handleInput(e, normalizeSexagesimal, (field) => (seconds = field), null)} />
- -