From 0840786b2eef1b19b2be312f047eb698b982ac26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Fri, 18 Sep 2026 12:01:32 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8F=B7=EF=B8=8F=20field-level=20e?= =?UTF-8?q?rrors=20for=20form=20inputs=20-=20Input=20and=20Textarea=20take?= =?UTF-8?q?=20an=20error=20message:=20shown=20under=20the=20field,=20the?= =?UTF-8?q?=20=20=20field=20marked=20aria-invalid=20and=20described=20by?= =?UTF-8?q?=20it=20-=20the=20backend's=20error=20body=20is=20{error,=20cod?= =?UTF-8?q?e}=20with=20no=20field=20name,=20so=20server=20=20=20failures?= =?UTF-8?q?=20stay=20in=20the=20form=20alert;=20field=20errors=20come=20fr?= =?UTF-8?q?om=20client=20checks=20-=20pilot:=20the=20new-class=20form=20ch?= =?UTF-8?q?ecks=20its=20name=20itself=20(noValidate),=20so=20a=20=20=20bla?= =?UTF-8?q?nk=20or=20spaces-only=20name=20is=20flagged=20in=20the=20app's?= =?UTF-8?q?=20words=20and=20not=20sent=20-=20test=20for=20the=20class=20na?= =?UTF-8?q?me=20check=20and=20its=20aria=20wiring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ui/input.tsx | 20 +++++++++++++++++--- src/components/ui/textarea.tsx | 22 ++++++++++++++++++---- src/i18n/messages.ts | 3 +++ src/pages/classes-page.test.tsx | 15 +++++++++++++++ src/pages/classes-page.tsx | 12 ++++++++++-- 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx index acab65c..a26f9d0 100644 --- a/src/components/ui/input.tsx +++ b/src/components/ui/input.tsx @@ -1,18 +1,32 @@ import type { ComponentProps } from "solid-js"; -import { splitProps } from "solid-js"; +import { Show, splitProps } from "solid-js"; import { cn } from "@/lib/cn"; -export type InputProps = ComponentProps<"input">; +export type InputProps = ComponentProps<"input"> & { + /** + * Message shown under the field. Marks it invalid and describes it for + * assistive tech; needs an `id` so the message can be linked. + */ + error?: string; +}; export function Input(props: InputProps) { - const [local, rest] = splitProps(props, ["class"]); + const [local, rest] = splitProps(props, ["class", "error"]); + const errorId = () => (props.id ? `${props.id}-error` : undefined); return ( + <> + +

{local.error}

+
+ ); } diff --git a/src/components/ui/textarea.tsx b/src/components/ui/textarea.tsx index bd4f700..355e7db 100644 --- a/src/components/ui/textarea.tsx +++ b/src/components/ui/textarea.tsx @@ -1,18 +1,32 @@ import type { ComponentProps } from "solid-js"; -import { splitProps } from "solid-js"; +import { Show, splitProps } from "solid-js"; import { cn } from "@/lib/cn"; -export type TextareaProps = ComponentProps<"textarea">; +export type TextareaProps = ComponentProps<"textarea"> & { + /** + * Message shown under the field. Marks it invalid and describes it for + * assistive tech; needs an `id` so the message can be linked. + */ + error?: string; +}; export function Textarea(props: TextareaProps) { - const [local, rest] = splitProps(props, ["class"]); + const [local, rest] = splitProps(props, ["class", "error"]); + const errorId = () => (props.id ? `${props.id}-error` : undefined); return ( + <>