You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
886 B
33 lines
886 B
2 years ago
|
import { useEffect, useRef } from 'react';
|
||
|
import type { InputRef } from '../Input';
|
||
|
|
||
|
export default function useRemovePasswordTimeout(
|
||
|
inputRef: React.RefObject<InputRef>,
|
||
|
triggerOnMount?: boolean,
|
||
|
) {
|
||
|
const removePasswordTimeoutRef = useRef<number[]>([]);
|
||
|
const removePasswordTimeout = () => {
|
||
|
removePasswordTimeoutRef.current.push(
|
||
|
window.setTimeout(() => {
|
||
|
if (
|
||
|
inputRef.current?.input &&
|
||
|
inputRef.current?.input.getAttribute('type') === 'password' &&
|
||
|
inputRef.current?.input.hasAttribute('value')
|
||
|
) {
|
||
|
inputRef.current?.input.removeAttribute('value');
|
||
|
}
|
||
|
}),
|
||
|
);
|
||
|
};
|
||
|
|
||
|
useEffect(() => {
|
||
|
if (triggerOnMount) {
|
||
|
removePasswordTimeout();
|
||
|
}
|
||
|
|
||
|
return () => removePasswordTimeoutRef.current.forEach(item => window.clearTimeout(item));
|
||
|
}, []);
|
||
|
|
||
|
return removePasswordTimeout;
|
||
|
}
|