mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
1719748a29
* chore: eslint add consistent-type-imports * fix avatar * Update Item.tsx
40 lines
930 B
TypeScript
40 lines
930 B
TypeScript
import * as React from 'react';
|
|
import { useRef } from 'react';
|
|
import { composeRef } from 'rc-util/lib/ref';
|
|
import raf from 'rc-util/lib/raf';
|
|
import type { TooltipProps } from '../tooltip';
|
|
import Tooltip 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;
|
|
});
|
|
}
|
|
|
|
React.useEffect(() => {
|
|
if (visible) {
|
|
keepAlign();
|
|
} else {
|
|
cancelKeepAlign();
|
|
}
|
|
|
|
return cancelKeepAlign;
|
|
}, [visible, props.title]);
|
|
|
|
return <Tooltip ref={composeRef(innerRef, ref)} {...props} />;
|
|
});
|
|
|
|
export default SliderTooltip;
|