mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
chore: Use rc-util composeRef (#27821)
This commit is contained in:
parent
696396a62f
commit
1a8bb04bf8
@ -1,19 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import { fillRef } from '../ref';
|
||||
|
||||
function useCombinedRefs<T>(
|
||||
...refs: Array<React.MutableRefObject<T> | ((instance: T) => void) | null>
|
||||
) {
|
||||
const targetRef = React.useRef<T>();
|
||||
|
||||
React.useEffect(() => {
|
||||
refs.forEach(ref => {
|
||||
if (!ref) return;
|
||||
fillRef(ref, targetRef.current);
|
||||
});
|
||||
}, [refs]);
|
||||
|
||||
return targetRef;
|
||||
}
|
||||
|
||||
export default useCombinedRefs;
|
@ -1,13 +1,13 @@
|
||||
import * as React from 'react';
|
||||
import { useRef } from 'react';
|
||||
import { composeRef } from 'rc-util/lib/ref';
|
||||
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 innerRef = useRef<any>(null);
|
||||
|
||||
const rafRef = React.useRef<number | null>(null);
|
||||
const rafRef = useRef<number | null>(null);
|
||||
|
||||
function cancelKeepAlign() {
|
||||
window.cancelAnimationFrame(rafRef.current!);
|
||||
@ -16,7 +16,7 @@ const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
||||
|
||||
function keepAlign() {
|
||||
rafRef.current = window.requestAnimationFrame(() => {
|
||||
(tooltipRef.current as any).forcePopupAlign();
|
||||
innerRef.current.forcePopupAlign();
|
||||
rafRef.current = null;
|
||||
keepAlign();
|
||||
});
|
||||
@ -32,7 +32,7 @@ const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
|
||||
return cancelKeepAlign;
|
||||
}, [visible]);
|
||||
|
||||
return <Tooltip ref={tooltipRef} {...props} />;
|
||||
return <Tooltip ref={composeRef(innerRef, ref)} {...props} />;
|
||||
});
|
||||
|
||||
export default SliderTooltip;
|
||||
|
Loading…
Reference in New Issue
Block a user