mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 08:39:07 +08:00
502dac12aa
* docs: fix code * feat: lint * feat: prettier * feat: test * feat: review * feat: format html * feat: format html
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
import * as React from 'react';
|
|
import { useRef } from 'react';
|
|
import type { SliderRef } from 'rc-slider/lib/Slider';
|
|
import raf from 'rc-util/lib/raf';
|
|
import { composeRef } from 'rc-util/lib/ref';
|
|
|
|
import type { TooltipProps } from '../tooltip';
|
|
import Tooltip from '../tooltip';
|
|
|
|
const SliderTooltip = React.forwardRef<SliderRef, 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} />;
|
|
});
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
SliderTooltip.displayName = 'SliderTooltip';
|
|
}
|
|
|
|
export default SliderTooltip;
|