Hungarian error messages; visible focus on input fields
CI / test (push) Successful in 1m47s
CI / build (push) Successful in 10m21s
CI / deploy (push) Skipped

- The browser's own form checks (required, minLength, e-mail format) show
  Hungarian text on every page (ValidationMessages in the root layout).
- User-facing backend errors are Hungarian: e-mail/password login, password
  length, links, invitations, sharing, questions, limits. Google/Apple token
  failures log the reason and tell the user to retry.
- errorText covers not_found, horoscope_unavailable and internal errors.
- Input fields: lighter background and gold caret on focus, the example text
  steps aside, so a click visibly lands in the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-22 10:14:15 +00:00
co-authored by Claude Opus 5.5
parent 4b93dc42e8
commit 9716f503bc
15 changed files with 139 additions and 31 deletions
+4 -1
View File
@@ -132,7 +132,10 @@ textarea.inp { padding: 12px 14px; line-height: 1.55; min-height: 96px; resize:
/* A button beside input fields is as tall as they are */
.row > .btn:not(.btn-sm), .redeem-row > .btn { min-height: 48px; }
.inp::placeholder { color: #8a93ab; }
.inp:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217, 180, 106, 0.25); }
.inp:focus { outline: none; border-color: var(--gold); background-color: #182037; box-shadow: 0 0 0 3px rgba(217, 180, 106, 0.25); }
/* Clicking in must visibly change the field: the example text steps aside for the caret */
.inp:focus::placeholder { color: transparent; }
.inp { caret-color: var(--gold); }
.inp:disabled { opacity: 0.55; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); min-height: 32px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--gold); margin: 0; }
+2
View File
@@ -5,6 +5,7 @@ import { Suspense } from "react";
import { NightSky } from "@/components/NightSky";
import { PaymentReturn } from "@/components/PaymentReturn";
import { SiteHeader } from "@/components/SiteHeader";
import { ValidationMessages } from "@/components/ValidationMessages";
import { getMe } from "@/lib/server";
import { siteUrl } from "@/lib/share";
@@ -32,6 +33,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
<html lang="hu" className={`${cormorant.variable} ${inter.variable}`}>
<body>
<NightSky />
<ValidationMessages />
{me && <SiteHeader me={me} />}
{children}
{me && (
@@ -0,0 +1,83 @@
"use client";
import { useEffect } from "react";
type Field = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
/** Hungarian text for a field the browser found invalid. */
function message(el: Field): string {
const v = el.validity;
if (v.valueMissing) {
if (el instanceof HTMLSelectElement) return "Válassz a listából.";
if (el instanceof HTMLInputElement && el.type === "checkbox") return "Jelöld be a folytatáshoz.";
if (el instanceof HTMLInputElement && el.type === "radio") return "Válassz egyet.";
return "Töltsd ki ezt a mezőt.";
}
if (v.typeMismatch) {
if (el.type === "email") return "Adj meg egy érvényes e-mail-címet.";
if (el.type === "url") return "Adj meg egy érvényes webcímet.";
}
if (v.tooShort && !(el instanceof HTMLSelectElement)) {
return `Legalább ${el.minLength} karakter legyen (most ${el.value.length}).`;
}
if (v.tooLong && !(el instanceof HTMLSelectElement)) return `Legfeljebb ${el.maxLength} karakter lehet.`;
if (el instanceof HTMLInputElement) {
if (v.rangeUnderflow) return `A legkisebb megengedett érték: ${el.min}.`;
if (v.rangeOverflow) return `A legnagyobb megengedett érték: ${el.max}.`;
if (v.patternMismatch) return el.title || "A formátum nem megfelelő.";
if (v.badInput && el.type === "number") return "Számot adj meg.";
}
return "Az érték nem megfelelő.";
}
function isField(t: EventTarget | null): t is Field {
return t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement;
}
/**
* The browser's own form checks (required, minLength, type="email"…) speak
* the browser's language. This puts Hungarian text into those bubbles on
* every page; the checks themselves stay the browser's.
*/
export function ValidationMessages() {
useEffect(() => {
// Fields whose message was set here, so it can be cleared again.
const marked = new WeakSet<Field>();
const clear = (el: Field) => {
if (marked.has(el)) {
el.setCustomValidity("");
marked.delete(el);
}
};
const onInvalid = (e: Event) => {
const el = e.target;
if (!isField(el)) return;
clear(el);
// A message the page set itself (setCustomValidity) is kept.
if (el.validity.customError || el.validity.valid) return;
el.setCustomValidity(message(el));
marked.add(el);
};
const onEdit = (e: Event) => {
if (isField(e.target)) clear(e.target);
};
// A submit attempt checks the fields afresh: a value set by code (no input event) is not stuck.
const onClick = (e: Event) => {
const button = (e.target as Element | null)?.closest?.("button, input[type=submit]");
const form = (button as HTMLButtonElement | HTMLInputElement | null)?.form;
if (!form || (button as HTMLButtonElement).type !== "submit") return;
for (const el of Array.from(form.elements)) if (isField(el)) clear(el);
};
document.addEventListener("invalid", onInvalid, true);
document.addEventListener("input", onEdit, true);
document.addEventListener("change", onEdit, true);
document.addEventListener("click", onClick, true);
return () => {
document.removeEventListener("invalid", onInvalid, true);
document.removeEventListener("input", onEdit, true);
document.removeEventListener("change", onEdit, true);
document.removeEventListener("click", onClick, true);
};
}, []);
return null;
}
+7
View File
@@ -37,6 +37,13 @@ export function errorText(e: unknown): string {
return "Ehhez nincs jogosultságod.";
case "insufficient_credits":
return "Nincs több részletes elemzésed ebből a fajtából.";
case "not_found":
return "Nem található. Lehet, hogy közben törölték.";
case "horoscope_unavailable":
return "A számítás most nem érhető el. Próbáld újra pár perc múlva.";
case "internal_error":
case "error":
return "Váratlan hiba történt. Próbáld újra később.";
default:
return e.message;
}