Added show password button for password fields
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { Input } from "@nextui-org/react";
|
||||
import { useField } from "formik";
|
||||
import { useState } from "react";
|
||||
import { EyeIcon, EyeSlashIcon } from "../icons";
|
||||
|
||||
interface NextUIFormikInputProps {
|
||||
label: string;
|
||||
@@ -16,15 +18,31 @@ const NextUIFormikInput = ({
|
||||
...props
|
||||
}: NextUIFormikInputProps) => {
|
||||
const [field, meta] = useField(props.name);
|
||||
const [inputType, setInputType] = useState(props.type);
|
||||
|
||||
return (
|
||||
<Input
|
||||
{...field}
|
||||
{...props}
|
||||
label={label}
|
||||
type={inputType}
|
||||
isInvalid={meta.touched && !!meta.error}
|
||||
errorMessage={meta.touched && meta.error ? meta.error : ""}
|
||||
startContent={startContent}
|
||||
endContent={
|
||||
props.type == "password" ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setInputType(inputType == "text" ? "password" : "text");
|
||||
}}
|
||||
>
|
||||
{inputType == "password" ? <EyeSlashIcon /> : <EyeIcon />}
|
||||
</button>
|
||||
</>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user