From ae005b8444aacc4071512f38031043156b6854c4 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Sat, 29 Aug 2020 00:22:27 +0300 Subject: hide error state onFocue input --- src/containers/Registration/Registration.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/containers/Registration/Registration.tsx b/src/containers/Registration/Registration.tsx index 709d04e..e7c8874 100644 --- a/src/containers/Registration/Registration.tsx +++ b/src/containers/Registration/Registration.tsx @@ -44,16 +44,16 @@ const useStyles = makeStyles(theme => ({ })); interface ErrorStates { - username: boolean; - email: boolean; - password: boolean; + username: boolean | undefined; + email: boolean | undefined; + password: boolean | undefined; } const Registration: React.FC = () => { const [errors, setErrors] = useState({ - username: false, - email: false, - password: false + username: undefined, + email: undefined, + password: undefined }); const [showPassword, setShowPassword] = useState(false); @@ -112,6 +112,13 @@ const Registration: React.FC = () => { e.target.value = e.target.value.toString().toLowerCase(); }; + const handleFocus = (value: string) => () => { + setErrors({ + ...errors, + [value]: undefined + }); + }; + return ( <>
Sign Up
@@ -124,6 +131,7 @@ const Registration: React.FC = () => { required onBlur={handleUsernameChange} onInput={handleToLowerCase} + onFocus={handleFocus('username')} /> { error={errors.email} helperText={errors.email && 'Invalid email address'} onBlur={handleEmailChange} + onFocus={handleFocus('email')} /> { helperText={errors.password && 'Should be at least 6 characters'} type={showPassword ? 'text' : 'password'} onBlur={handlePasswordChange} + onFocus={handleFocus('password')} InputProps={{ endAdornment: ( -- cgit v1.2.3