2022-06-22 14:57:09 +08:00
|
|
|
import raf from 'rc-util/lib/raf';
|
|
|
|
import { composeRef } from 'rc-util/lib/ref';
|
2020-01-06 20:09:12 +08:00
|
|
|
import * as React from 'react';
|
2020-11-17 12:01:02 +08:00
|
|
|
import { useRef } from 'react';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { TooltipProps } from '../tooltip';
|
|
|
|
import Tooltip from '../tooltip';
|
2020-05-15 10:47:03 +08:00
|
|
|
|
|
|
|
const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
2020-01-06 20:09:12 +08:00
|
|
|
const { visible } = props;
|
2020-11-17 12:01:02 +08:00
|
|
|
const innerRef = useRef<any>(null);
|
2020-01-06 20:09:12 +08:00
|
|
|
|
2020-11-17 12:01:02 +08:00
|
|
|
const rafRef = useRef<number | null>(null);
|
2020-01-06 20:09:12 +08:00
|
|
|
|
|
|
|
function cancelKeepAlign() {
|
2020-11-20 12:11:50 +08:00
|
|
|
raf.cancel(rafRef.current!);
|
2020-01-06 20:09:12 +08:00
|
|
|
rafRef.current = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function keepAlign() {
|
2020-11-20 12:11:50 +08:00
|
|
|
rafRef.current = raf(() => {
|
2021-01-05 21:50:07 +08:00
|
|
|
innerRef.current?.forcePopupAlign();
|
2020-01-06 20:09:12 +08:00
|
|
|
rafRef.current = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (visible) {
|
|
|
|
keepAlign();
|
|
|
|
} else {
|
|
|
|
cancelKeepAlign();
|
|
|
|
}
|
|
|
|
|
|
|
|
return cancelKeepAlign;
|
2021-02-10 15:53:07 +08:00
|
|
|
}, [visible, props.title]);
|
2020-01-06 20:09:12 +08:00
|
|
|
|
2020-11-17 12:01:02 +08:00
|
|
|
return <Tooltip ref={composeRef(innerRef, ref)} {...props} />;
|
2020-05-15 10:47:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export default SliderTooltip;
|