Browse Source
* fix(Input): should not have value prop on input when click toggle icon * fix: 修改参数名 * fix: 修改传参pull/38005/head
linxianxi
2 years ago
committed by
GitHub
4 changed files with 58 additions and 21 deletions
@ -0,0 +1,32 @@ |
|||
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; |
|||
} |
Loading…
Reference in new issue