mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +02:00
💄 Add form validation feedback (#998)
This commit is contained in:
parent
63c6c4f92d
commit
c04a670607
2 changed files with 8 additions and 4 deletions
|
@ -166,7 +166,9 @@ const Discussion: React.FunctionComponent = () => {
|
|||
key={session.user?.id}
|
||||
control={control}
|
||||
rules={{ validate: requiredString }}
|
||||
render={({ field }) => <NameInput {...field} />}
|
||||
render={({ field }) => (
|
||||
<NameInput error={!!formState.errors.authorName} {...field} />
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-between gap-2">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import clsx from "clsx";
|
||||
import { cn } from "@rallly/ui";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import * as React from "react";
|
||||
|
||||
|
@ -11,12 +11,13 @@ interface NameInputProps
|
|||
> {
|
||||
value?: string;
|
||||
defaultValue?: string;
|
||||
error?: boolean;
|
||||
}
|
||||
|
||||
const NameInput: React.ForwardRefRenderFunction<
|
||||
HTMLInputElement,
|
||||
NameInputProps
|
||||
> = ({ value, defaultValue, className, ...forwardProps }, ref) => {
|
||||
> = ({ value, defaultValue, className, error, ...forwardProps }, ref) => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="relative flex items-center">
|
||||
|
@ -28,10 +29,11 @@ const NameInput: React.ForwardRefRenderFunction<
|
|||
) : null}
|
||||
<input
|
||||
ref={ref}
|
||||
className={clsx(
|
||||
className={cn(
|
||||
"input",
|
||||
{
|
||||
"pl-9": value || defaultValue,
|
||||
"ring-destructive ring-1": error,
|
||||
},
|
||||
className,
|
||||
)}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue