v1.6.2: Zeiteingabe – Auto-Doppelpunkt nach 2 Ziffern, Endzeit leer bei Fokus

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-11 20:41:54 +02:00
parent 38af0634ca
commit ab9be7b96f
3 changed files with 30 additions and 3 deletions
+1
View File
@@ -250,6 +250,7 @@ export default function LogbuchForm({ kuppel, currentUserBeo, editEntry, onSaved
<TimeInput <TimeInput
value={ende.slice(11, 16)} value={ende.slice(11, 16)}
onChange={(t) => setEnde(ende.slice(0, 10) + 'T' + t)} onChange={(t) => setEnde(ende.slice(0, 10) + 'T' + t)}
clearOnFocus
className="w-24" className="w-24"
/> />
</div> </div>
+28 -2
View File
@@ -6,6 +6,7 @@ interface Props {
value: string; // "HH:MM" value: string; // "HH:MM"
onChange: (value: string) => void; onChange: (value: string) => void;
className?: string; className?: string;
clearOnFocus?: boolean;
} }
function isValid(t: string): boolean { function isValid(t: string): boolean {
@@ -19,7 +20,7 @@ function normalize(t: string): string {
return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`; return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`;
} }
export default function TimeInput({ value, onChange, className = '' }: Props) { export default function TimeInput({ value, onChange, className = '', clearOnFocus = false }: Props) {
const [local, setLocal] = useState(value); const [local, setLocal] = useState(value);
const [error, setError] = useState(false); const [error, setError] = useState(false);
@@ -28,7 +29,29 @@ export default function TimeInput({ value, onChange, className = '' }: Props) {
setError(false); setError(false);
}, [value]); }, [value]);
function handleChange(raw: string) {
setError(false);
// Auto-insert colon after the 2nd digit (only when adding, not deleting)
if (/^\d{2}$/.test(raw) && /^\d$/.test(local)) {
setLocal(raw + ':');
return;
}
setLocal(raw);
}
function handleFocus() {
if (clearOnFocus) {
setLocal('');
setError(false);
}
}
function handleBlur() { function handleBlur() {
if (local === '') {
setLocal(value);
setError(false);
return;
}
if (isValid(local)) { if (isValid(local)) {
const norm = normalize(local); const norm = normalize(local);
setLocal(norm); setLocal(norm);
@@ -43,10 +66,13 @@ export default function TimeInput({ value, onChange, className = '' }: Props) {
<div className={`relative ${className}`}> <div className={`relative ${className}`}>
<input <input
type="text" type="text"
inputMode="numeric"
value={local} value={local}
onChange={(e) => { setLocal(e.target.value); setError(false); }} onChange={(e) => handleChange(e.target.value)}
onFocus={handleFocus}
onBlur={handleBlur} onBlur={handleBlur}
placeholder="HH:MM" placeholder="HH:MM"
maxLength={5}
className={`w-full px-2 py-1 border-2 rounded-lg bg-white text-sm text-gray-900 font-mono text-center focus:outline-none ${ className={`w-full px-2 py-1 border-2 rounded-lg bg-white text-sm text-gray-900 font-mono text-center focus:outline-none ${
error ? 'border-red-500 focus:border-red-500' : 'border-gray-400 focus:border-blue-500' error ? 'border-red-500 focus:border-red-500' : 'border-gray-400 focus:border-blue-500'
}`} }`}
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "logbuch", "name": "logbuch",
"version": "1.6.1", "version": "1.6.2",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",