ant-design/components/slider/SliderTooltip.tsx
muxin 76b6909c2d
fix: forcePopupAlign is align to forceAlign instead (#41540)
* fix: forcePopupAlign is align to forceAlign instead

* test: add test

* test: update test
2023-03-30 14:45:15 +08:00

40 lines
916 B
TypeScript

import raf from 'rc-util/lib/raf';
import { composeRef } from 'rc-util/lib/ref';
import * as React from 'react';
import { useRef } from 'react';
import type { TooltipProps } from '../tooltip';
import Tooltip from '../tooltip';
const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
const { open } = 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?.forceAlign();
rafRef.current = null;
});
}
React.useEffect(() => {
if (open) {
keepAlign();
} else {
cancelKeepAlign();
}
return cancelKeepAlign;
}, [open, props.title]);
return <Tooltip ref={composeRef(innerRef, ref)} {...props} />;
});
export default SliderTooltip;