From 368c9ee3d7015f21b27c0a53f922ae96e231bdc7 Mon Sep 17 00:00:00 2001 From: Lenin Alevski Date: Tue, 20 Sep 2022 21:13:34 -0700 Subject: [PATCH] InputBoxWrapper automatically add hide/show behavior for password fields (#2327) Signed-off-by: Lenin Alevski --- .../InputBoxWrapper/InputBoxWrapper.tsx | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/portal-ui/src/screens/Console/Common/FormComponents/InputBoxWrapper/InputBoxWrapper.tsx b/portal-ui/src/screens/Console/Common/FormComponents/InputBoxWrapper/InputBoxWrapper.tsx index f680c6a7e..6aadfb1ac 100644 --- a/portal-ui/src/screens/Console/Common/FormComponents/InputBoxWrapper/InputBoxWrapper.tsx +++ b/portal-ui/src/screens/Console/Common/FormComponents/InputBoxWrapper/InputBoxWrapper.tsx @@ -13,7 +13,7 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import React from "react"; +import React, { useState } from "react"; import { Grid, IconButton, @@ -24,6 +24,8 @@ import { } from "@mui/material"; import { OutlinedInputProps } from "@mui/material/OutlinedInput"; import { InputProps as StandardInputProps } from "@mui/material/Input"; +import VisibilityOffIcon from "@mui/icons-material/VisibilityOff"; +import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye"; import { Theme } from "@mui/material/styles"; import createStyles from "@mui/styles/createStyles"; import makeStyles from "@mui/styles/makeStyles"; @@ -137,6 +139,7 @@ const InputBoxWrapper = ({ onFocus, }: InputBoxProps) => { let inputProps: any = { "data-index": index, ...extraInputProps }; + const [toggleTextInput, setToggleTextInput] = useState(false); if (type === "number" && min) { inputProps["min"] = min; @@ -150,6 +153,18 @@ const InputBoxWrapper = ({ inputProps["pattern"] = pattern; } + let inputBoxWrapperIcon = overlayIcon; + let inputBoxWrapperType = type; + + if (type === "password" && overlayIcon === null) { + inputBoxWrapperIcon = toggleTextInput ? ( + + ) : ( + + ); + inputBoxWrapperType = toggleTextInput ? "text" : "password"; + } + return ( - {overlayIcon && ( + {inputBoxWrapperIcon && (
{ overlayAction(); } - : () => null + : () => setToggleTextInput(!toggleTextInput) } id={overlayId} size={"small"} @@ -222,7 +237,7 @@ const InputBoxWrapper = ({ disableRipple={false} disableTouchRipple={false} > - {overlayIcon} + {inputBoxWrapperIcon}
)}