mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 03:14:07 +08:00
502dac12aa
* docs: fix code * feat: lint * feat: prettier * feat: test * feat: review * feat: format html * feat: format html
39 lines
958 B
TypeScript
39 lines
958 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
import type { InputRef } from '../Input';
|
|
|
|
export default function useRemovePasswordTimeout(
|
|
inputRef: React.RefObject<InputRef>,
|
|
triggerOnMount?: boolean,
|
|
) {
|
|
const removePasswordTimeoutRef = useRef<ReturnType<typeof setTimeout>[]>([]);
|
|
const removePasswordTimeout = () => {
|
|
removePasswordTimeoutRef.current.push(
|
|
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((timer) => {
|
|
if (timer) {
|
|
clearTimeout(timer);
|
|
}
|
|
});
|
|
}, []);
|
|
|
|
return removePasswordTimeout;
|
|
}
|