diff --git a/package.json b/package.json index cc21552..3844975 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@babel/runtime": "^7.18.3", "@rc-component/trigger": "^2.0.0", "classnames": "^2.2.6", - "rc-util": "^5.17.0" + "rc-util": "^5.44.1" }, "devDependencies": { "@rc-component/father-plugin": "^1.0.0", diff --git a/src/Dropdown.tsx b/src/Dropdown.tsx index f461d68..920e443 100644 --- a/src/Dropdown.tsx +++ b/src/Dropdown.tsx @@ -7,8 +7,7 @@ import type { BuildInPlacements, } from '@rc-component/trigger/lib/interface'; import classNames from 'classnames'; -import { composeRef, supportRef } from 'rc-util/lib/ref'; -import type { ReactElement } from 'react'; +import { composeRef, getNodeRef, supportRef } from 'rc-util/lib/ref'; import React from 'react'; import useAccessibility from './hooks/useAccessibility'; import Overlay from './Overlay'; @@ -139,10 +138,7 @@ function Dropdown(props: DropdownProps, ref) { mergedVisible && getOpenClassName(), ), ref: supportRef(children) - ? composeRef( - childRef, - (children as ReactElement & { ref: React.Ref }).ref, - ) + ? composeRef(childRef, getNodeRef(children)) : undefined, }); diff --git a/src/Overlay.tsx b/src/Overlay.tsx index ee1c539..6b05dfe 100644 --- a/src/Overlay.tsx +++ b/src/Overlay.tsx @@ -1,11 +1,14 @@ -import React, { forwardRef, ReactElement, useMemo } from 'react'; +import { composeRef, getNodeRef, supportRef } from 'rc-util/lib/ref'; +import React, { forwardRef, useMemo } from 'react'; import type { DropdownProps } from './Dropdown'; -import { composeRef, supportRef } from 'rc-util/lib/ref'; -export type OverlayProps = Pick +export type OverlayProps = Pick< + DropdownProps, + 'overlay' | 'arrow' | 'prefixCls' +>; const Overlay = forwardRef((props, ref) => { - const {overlay, arrow, prefixCls} = props; + const { overlay, arrow, prefixCls } = props; const overlayNode = useMemo(() => { let overlayElement: React.ReactElement; @@ -17,14 +20,16 @@ const Overlay = forwardRef((props, ref) => { return overlayElement; }, [overlay]); - const composedRef = composeRef(ref, (overlayNode as ReactElement & {ref: React.Ref})?.ref); + const composedRef = composeRef(ref, getNodeRef(overlayNode)); return ( <> {arrow &&
} - {React.cloneElement(overlayNode, { ref: supportRef(overlayNode) ? composedRef : undefined })} + {React.cloneElement(overlayNode, { + ref: supportRef(overlayNode) ? composedRef : undefined, + })} - ) + ); }); -export default Overlay; \ No newline at end of file +export default Overlay;