diff --git a/package.json b/package.json index d5c48a6..6b6c22e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ }, "dependencies": { "@babel/runtime": "^7.11.2", - "@rc-component/trigger": "^1.17.0", + "@rc-component/trigger": "^1.18.0", "classnames": "^2.3.1" }, "devDependencies": { diff --git a/src/Tooltip.tsx b/src/Tooltip.tsx index 1cfc415..944f711 100644 --- a/src/Tooltip.tsx +++ b/src/Tooltip.tsx @@ -43,6 +43,7 @@ export interface TooltipProps } export interface TooltipRef { + nativeElement: HTMLElement; forceAlign: VoidFunction; } @@ -74,7 +75,7 @@ const Tooltip = (props: TooltipProps, ref: React.Ref) => { } = props; const triggerRef = useRef(null); - useImperativeHandle(ref, () => triggerRef.current as TriggerRef); + useImperativeHandle(ref, () => triggerRef.current); const extraProps: Partial = { ...restProps }; if ('visible' in props) { diff --git a/tests/index.test.tsx b/tests/index.test.tsx index e852993..d167d0c 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -1,6 +1,6 @@ import { act, fireEvent, render } from '@testing-library/react'; import React from 'react'; -import Tooltip from '../src'; +import Tooltip, { TooltipRef } from '../src'; const verifyContent = (wrapper: HTMLElement, content: string) => { expect(wrapper.querySelector('.x-content').textContent).toBe(content); @@ -188,7 +188,7 @@ describe('rc-tooltip', () => { placement="left" overlay={Tooltip content} showArrow={{ - className: 'abc' + className: 'abc', }} >
Click this
@@ -239,4 +239,16 @@ describe('rc-tooltip', () => { fireEvent.click(container.querySelector('.target')); expect(container.querySelector('.x-content')).toBeTruthy(); }); + + it('ref support nativeElement', () => { + const nodeRef = React.createRef(); + + const { container } = render( + }> +