Skip to content

Commit

Permalink
add visibility icon
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jun 26, 2024
1 parent de5f0de commit 099dc1e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/components/form/PasswordField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Security as SecurityIcon } from "@mui/icons-material"
import { InputAdornment } from "@mui/material"
import type { FC } from "react"
import {
Visibility as VisibilityIcon,
VisibilityOff as VisibilityOffIcon,
} from "@mui/icons-material"
import { IconButton, InputAdornment } from "@mui/material"
import { useState, type FC } from "react"
import { string as YupString } from "yup"

import TextField, { type TextFieldProps } from "./TextField"
Expand All @@ -19,17 +22,26 @@ const PasswordField: FC<PasswordFieldProps> = ({
InputProps = {},
...otherTextFieldProps
}) => {
const [isVisible, setIsVisible] = useState(false)

return (
<TextField
type="password"
type={isVisible ? "text" : "password"}
name={name}
label={label}
schema={schema}
placeholder={placeholder}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<SecurityIcon />
<IconButton
onClick={() => {
setIsVisible(previousIsVisible => !previousIsVisible)
}}
edge="end"
>
{isVisible ? <VisibilityIcon /> : <VisibilityOffIcon />}
</IconButton>
</InputAdornment>
),
...InputProps,
Expand Down

0 comments on commit 099dc1e

Please sign in to comment.