Change hover cards to not appear until the mouse stops in web UI (#30850)
This commit is contained in:
parent
20fa9ce484
commit
b728c0e8ce
6 changed files with 131 additions and 55 deletions
|
@ -2,19 +2,34 @@ import { useRef, useCallback, useEffect } from 'react';
|
|||
|
||||
export const useTimeout = () => {
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
||||
const callbackRef = useRef<() => void>();
|
||||
|
||||
const set = useCallback((callback: () => void, delay: number) => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
|
||||
callbackRef.current = callback;
|
||||
timeoutRef.current = setTimeout(callback, delay);
|
||||
}, []);
|
||||
|
||||
const delay = useCallback((delay: number) => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
|
||||
if (!callbackRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
timeoutRef.current = setTimeout(callbackRef.current, delay);
|
||||
}, []);
|
||||
|
||||
const cancel = useCallback(() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = undefined;
|
||||
callbackRef.current = undefined;
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
@ -25,5 +40,5 @@ export const useTimeout = () => {
|
|||
[cancel],
|
||||
);
|
||||
|
||||
return [set, cancel] as const;
|
||||
return [set, cancel, delay] as const;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue