Skip to content

Commit

Permalink
added error prop support for textarea
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
tareq1988 committed Sep 24, 2023
1 parent acb66ad commit 887fb03
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Components/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ interface TextareaProps {
value?: string;
required?: boolean;
rows?: number;
error?: React.ReactNode;
onChange?: (value: string) => void;
}

const Textarea: React.FC<TextareaProps> = ({
label,
help,
error,
className,
onChange,
disabled = false,
Expand All @@ -42,7 +44,8 @@ const Textarea: React.FC<TextareaProps> = ({
'block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6',
className,
disabled &&
'disabled:cursor-not-allowed disabled:bg-gray-50 disabled:text-gray-500 disabled:ring-gray-200'
'disabled:cursor-not-allowed disabled:bg-gray-50 disabled:text-gray-500 disabled:ring-gray-200',
error && 'ring-red-300 text-red-900 placeholder:text-red-300 focus:ring-red-500'
)}
defaultValue={''}
onChange={(e) => onChange && onChange(e.target.value)}
Expand All @@ -52,6 +55,7 @@ const Textarea: React.FC<TextareaProps> = ({
/>

{help && <div className="text-gray-500 text-sm mt-2">{help}</div>}
{error && <p className="text-red-600 text-sm mt-2">{error}</p>}
</div>
</div>
);
Expand Down

0 comments on commit 887fb03

Please sign in to comment.