Skip to content

Commit

Permalink
added error prop support for select input
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
tareq1988 committed Sep 24, 2023
1 parent 887fb03 commit 850157a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Components/SelectInput/SelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Option {
interface SelectProps {
label?: string;
help?: React.ReactNode;
error?: React.ReactNode;
required?: boolean;
options: Option[];
selectedKey?: string;
Expand All @@ -20,6 +21,7 @@ interface SelectProps {
const SelectInput: React.FC<SelectProps> = ({
label,
help,
error,
options,
required = false,
selectedKey,
Expand Down Expand Up @@ -59,7 +61,8 @@ const SelectInput: React.FC<SelectProps> = ({
<select
className={twMerge(
'block w-full rounded-md border-0 py-1.5 px-2 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 outline-none',
className
className,
error && 'ring-red-300 text-red-900 placeholder:text-red-300 focus:ring-red-500'
)}
value={selectedOption.key}
onChange={handleChange}
Expand All @@ -74,6 +77,7 @@ const SelectInput: React.FC<SelectProps> = ({
</select>

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

0 comments on commit 850157a

Please sign in to comment.