import React, { useRef } from 'react'; import { Box, Flex, FormControl, FormLabel, Text, IconButton, Input, InputGroup, InputProps, InputRightElement, InputLeftElement, Icon, useDisclosure, useMergeRefs, useColorModeValue as mode, } from '@chakra-ui/react'; import { HiEye, HiEyeOff } from 'react-icons/hi'; import { MdVpnKey } from 'react-icons/md'; interface PasswordFieldPropsType extends InputProps { errorMessage?: string | undefined; } export const PasswordField = React.forwardRef((props, ref) => { const { errorMessage, ...other } = props; const { isOpen, onToggle } = useDisclosure(); const inputRef = useRef(null); const mergeRef = useMergeRefs(inputRef, ref); const onClickReveal = () => { onToggle(); const input = inputRef.current; if (input) { input.focus({ preventScroll: true }); const length = input.value.length * 2; requestAnimationFrame(() => { input.setSelectionRange(length, length); }); } }; return ( Password } /> : } onClick={onClickReveal} /> {errorMessage && ( {errorMessage} )} ); });