Skip to content

Commit

Permalink
style: added validation colors to the label and error message
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurparalkar committed Apr 16, 2024
1 parent 669816a commit 7a125a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ function App() {
handleSubmit,
reset,
formState: { errors },
} = useForm<TFormValues>({
shouldUseNativeValidation: true,
});
} = useForm<TFormValues>();

const onSubmit = (data: TFormValues) => {
console.log("form Data = ", data);
Expand Down
10 changes: 8 additions & 2 deletions src/components/fields/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ const InputField = (props: InputFieldProps) => {
return (
<>
<div className="flex flex-col space-y-2 my-2">
<Label htmlFor={htmlFor}>{labelText}</Label>
<Label className={`${error ? "text-red-600" : ""}`} htmlFor={htmlFor}>
{labelText}
</Label>
<Input
id="htmlFor"
{...rest}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{...register(htmlFor, { ...validation })}
/>
{error && <span>{error.message}</span>}
{error && (
<span className="text-xs text-red-600 font-semibold">
{error.message}
</span>
)}
</div>
</>
);
Expand Down

0 comments on commit 7a125a7

Please sign in to comment.