From 987c4ecc67dc3cd41d0db04727c942efe35d5c82 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Fri, 28 Aug 2020 19:21:11 +0300 Subject: change onChange to onBlur event --- src/containers/Registration/Registration.tsx | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/containers') diff --git a/src/containers/Registration/Registration.tsx b/src/containers/Registration/Registration.tsx index 3269f6e..e250397 100644 --- a/src/containers/Registration/Registration.tsx +++ b/src/containers/Registration/Registration.tsx @@ -79,21 +79,29 @@ const Registration: React.FC = () => { const handleLogin = () => { history.push('/login'); }; - const handleClickShowPassword = () => { setShowPassword(prevState => !prevState); }; const handleMouseDownPassword = (event: React.MouseEvent) => { event.preventDefault(); }; - const handleUsernameChange = (e: React.ChangeEvent) => { - setValues({ ...values, username: e.currentTarget.value.length > 0 }); + const handleUsernameChange = (e: React.FocusEvent) => { + setValues({ + ...values, + username: e.currentTarget.value.length > 0 + }); }; - const handleEmailChange = (e: React.ChangeEvent) => { - setValues({ ...values, email: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(e.currentTarget.value) }); + const handleEmailChange = (e: React.FocusEvent) => { + setValues({ + ...values, + email: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(e.currentTarget.value) + }); }; - const handlePasswordChange = (e: React.ChangeEvent) => { - setValues({ ...values, password: e.currentTarget.value.length > 6 }); + const handlePasswordChange = (e: React.FocusEvent) => { + setValues({ + ...values, + password: e.currentTarget.value.length > 6 + }); }; return ( @@ -106,14 +114,14 @@ const Registration: React.FC = () => { error={!values.username} helperText={!values.username && 'This field is required'} required - onChange={handleUsernameChange} + onBlur={handleUsernameChange} /> { error={!values.password} helperText={!values.password && 'Should be at least 6 characters'} type={showPassword ? 'text' : 'password'} - onChange={handlePasswordChange} + onBlur={handlePasswordChange} InputProps={{ endAdornment: ( -- cgit v1.2.3