mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-26 20:20:00 +08:00
179ee276c9
* improve: useCombinedRefs code * change location
39 lines
957 B
TypeScript
39 lines
957 B
TypeScript
import * as React from 'react';
|
|
import Tooltip, { TooltipProps } from '../tooltip';
|
|
import useCombinedRefs from '../_util/hooks/useCombinedRefs';
|
|
|
|
const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
|
const { visible } = props;
|
|
const innerRef = React.useRef<any>(null);
|
|
const tooltipRef = useCombinedRefs(ref, innerRef);
|
|
|
|
const rafRef = React.useRef<number | null>(null);
|
|
|
|
function cancelKeepAlign() {
|
|
window.cancelAnimationFrame(rafRef.current!);
|
|
rafRef.current = null;
|
|
}
|
|
|
|
function keepAlign() {
|
|
rafRef.current = window.requestAnimationFrame(() => {
|
|
(tooltipRef.current as any).forcePopupAlign();
|
|
rafRef.current = null;
|
|
keepAlign();
|
|
});
|
|
}
|
|
|
|
React.useEffect(() => {
|
|
if (visible) {
|
|
keepAlign();
|
|
} else {
|
|
cancelKeepAlign();
|
|
}
|
|
|
|
return cancelKeepAlign;
|
|
}, [visible]);
|
|
|
|
return <Tooltip ref={tooltipRef} {...props} />;
|
|
});
|
|
|
|
export default SliderTooltip;
|