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.

40 lines
906 B

import * as React from 'react';
import { useRef } from 'react';
import { composeRef } from 'rc-util/lib/ref';
import raf from 'rc-util/lib/raf';
import Tooltip, { TooltipProps } from '../tooltip';
const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
const { visible } = props;
const innerRef = useRef<any>(null);
const rafRef = useRef<number | null>(null);
function cancelKeepAlign() {
raf.cancel(rafRef.current!);
rafRef.current = null;
}
function keepAlign() {
rafRef.current = raf(() => {
innerRef.current?.forcePopupAlign();
rafRef.current = null;
keepAlign();
});
}
React.useEffect(() => {
if (visible) {
keepAlign();
} else {
cancelKeepAlign();
}
return cancelKeepAlign;
}, [visible]);
return <Tooltip ref={composeRef(innerRef, ref)} {...props} />;
});
export default SliderTooltip;