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 ( + <>