|
1 | 1 | import { Visibility, VisibilityOff } from "@mui/icons-material";
|
2 |
| -import { IconButton, InputAdornment, TextField, TextFieldPropsSizeOverrides, TextFieldVariants } from "@mui/material"; |
| 2 | +import { IconButton, InputAdornment, TextField, TextFieldPropsSizeOverrides, TextFieldVariants, Tooltip } from "@mui/material"; |
3 | 3 | import { OverridableStringUnion } from '@mui/types';
|
4 | 4 | import { useState } from "react";
|
5 | 5 |
|
| 6 | +const passwordRequirements = ( |
| 7 | + <ul style={{ paddingLeft: "12px", margin: 0 }}> |
| 8 | + <li>At least 8 characters long</li> |
| 9 | + <li>At least 1 lowercase letter</li> |
| 10 | + <li>At least 1 uppercase letter</li> |
| 11 | + <li>At least 1 digit</li> |
| 12 | + <li>At least 1 special character</li> |
| 13 | + </ul> |
| 14 | +); |
| 15 | + |
6 | 16 | // Adapted from https://muhimasri.com/blogs/mui-validation/
|
7 | 17 | type CustomTextFieldProps = {
|
8 | 18 | label: string;
|
@@ -41,27 +51,30 @@ const CustomTextField: React.FC<CustomTextFieldProps> = ({
|
41 | 51 | };
|
42 | 52 |
|
43 | 53 | return (
|
44 |
| - <TextField |
45 |
| - label={label} |
46 |
| - variant={variant} |
47 |
| - size={size} |
48 |
| - required={required} |
49 |
| - onChange={handleChange} |
50 |
| - error={(required && emptyField) || !!error} |
51 |
| - helperText={error} |
52 |
| - type={showPassword ? "text" : "password"} |
53 |
| - slotProps={{ |
54 |
| - input: { |
55 |
| - endAdornment: isPasswordField && ( |
56 |
| - <InputAdornment position="end"> |
57 |
| - <IconButton onClick={() => setShowPassword(!showPassword)} edge="end"> |
58 |
| - {showPassword ? <VisibilityOff /> : <Visibility />} |
59 |
| - </IconButton> |
60 |
| - </InputAdornment> |
61 |
| - ), |
62 |
| - } |
63 |
| - }} |
64 |
| - /> |
| 54 | + <Tooltip title={isPasswordField && passwordRequirements} placement="right" arrow> |
| 55 | + <TextField |
| 56 | + label={label} |
| 57 | + variant={variant} |
| 58 | + size={size} |
| 59 | + fullWidth |
| 60 | + required={required} |
| 61 | + onChange={handleChange} |
| 62 | + error={(required && emptyField) || !!error} |
| 63 | + helperText={error} |
| 64 | + type={showPassword ? "text" : "password"} |
| 65 | + slotProps={{ |
| 66 | + input: { |
| 67 | + endAdornment: isPasswordField && ( |
| 68 | + <InputAdornment position="end"> |
| 69 | + <IconButton onClick={() => setShowPassword(!showPassword)} edge="end"> |
| 70 | + {showPassword ? <VisibilityOff /> : <Visibility />} |
| 71 | + </IconButton> |
| 72 | + </InputAdornment> |
| 73 | + ), |
| 74 | + } |
| 75 | + }} |
| 76 | + /> |
| 77 | + </Tooltip> |
65 | 78 | );
|
66 | 79 | };
|
67 | 80 |
|
|
0 commit comments