mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
6b658dab76
* feat: switch visible to open for Tooltip & Popover & Popconfirm * fix lint * fix: merge state * chore: Update ts part * test: add legacy test * test: fix test case Co-authored-by: 二货机器人 <smith3816@gmail.com>
40 lines
921 B
TypeScript
40 lines
921 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?.forcePopupAlign();
|
|
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;
|