diff --git a/components/ui/Input.tsx b/components/ui/Input.tsx index 93c48c1..9802c39 100644 --- a/components/ui/Input.tsx +++ b/components/ui/Input.tsx @@ -1,4 +1,4 @@ -import { forwardRef } from "react"; +import { forwardRef, useId } from "react"; import { cn } from "@/lib/utils/cn"; interface InputProps extends React.InputHTMLAttributes { @@ -8,13 +8,22 @@ interface InputProps extends React.InputHTMLAttributes { } export const Input = forwardRef(function Input( - { error, prefix, suffix, className, ...props }, + { error, prefix, suffix, className, id: propsId, ...props }, ref, ) { + const generatedId = useId(); + const id = propsId ?? generatedId; + const errorId = `${id}-error`; + const describedBy = + [error && errorId, props["aria-describedby"]].filter(Boolean).join(" ") || + undefined; return (
{prefix && ( - + )} @@ -30,13 +39,23 @@ export const Input = forwardRef(function Input( className, )} {...props} + id={id} + aria-invalid={error ? true : undefined} + aria-describedby={describedBy} /> {suffix && ( - + )} - {error &&

{error}

} + {error && ( + + )}
); });