From 09f8f579f15c807071ae161498bc568f72578e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 10 Jul 2026 17:02:45 +0800 Subject: [PATCH] feat: support disabled prop --- README.md | 1 + docs/demo/disabled.md | 12 ++++++++++++ docs/examples/disabled.tsx | 19 +++++++++++++++++++ package.json | 2 +- src/Tooltip.tsx | 1 + tests/index.test.tsx | 26 ++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 docs/demo/disabled.md create mode 100644 docs/examples/disabled.tsx diff --git a/README.md b/README.md index cb5e9ed3..42515f01 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Then open `http://localhost:8000`. | `classNames` | `Partial>` | - | Semantic class names for root, arrow, and container nodes. | | `defaultVisible` | boolean | - | Initial uncontrolled visible state. | | `destroyOnHidden` | boolean | false | Destroy popup DOM when hidden. | +| `disabled` | boolean | false | Temporarily hide tooltip while preserving visible state. | | `fresh` | boolean | - | Keep popup content fresh when closed. | | `getTooltipContainer` | `(node: HTMLElement) => HTMLElement` | - | Resolve popup container. | | `id` | string | generated id | Tooltip id used for accessibility. | diff --git a/docs/demo/disabled.md b/docs/demo/disabled.md new file mode 100644 index 00000000..3f119afa --- /dev/null +++ b/docs/demo/disabled.md @@ -0,0 +1,12 @@ +--- +title: Disabled +order: 9 +--- + +Hover the button to show the Tooltip. Click it to toggle `disabled`. + +```jsx +import DisabledDemo from '../examples/disabled'; + +export default () => ; +``` diff --git a/docs/examples/disabled.tsx b/docs/examples/disabled.tsx new file mode 100644 index 00000000..5231183b --- /dev/null +++ b/docs/examples/disabled.tsx @@ -0,0 +1,19 @@ +import React, { useState } from 'react'; +import '../../assets/bootstrap.less'; +import Tooltip from '../../src'; + +const DisabledDemo = () => { + const [disabled, setDisabled] = useState(false); + + return ( +
+ + + +
+ ); +}; + +export default DisabledDemo; diff --git a/package.json b/package.json index a67a0266..d6977f81 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "prepare": "husky" }, "dependencies": { - "@rc-component/trigger": "^3.7.1", + "@rc-component/trigger": "^3.10.0", "@rc-component/util": "^1.11.1", "clsx": "^2.1.1" }, diff --git a/src/Tooltip.tsx b/src/Tooltip.tsx index 17e8d7aa..5aaa8daf 100644 --- a/src/Tooltip.tsx +++ b/src/Tooltip.tsx @@ -19,6 +19,7 @@ export interface TooltipProps extends Pick< TriggerProps, | 'onPopupAlign' | 'builtinPlacements' + | 'disabled' | 'fresh' | 'mouseLeaveDelay' | 'mouseEnterDelay' diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 1363e5ed..d8c89d98 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -304,6 +304,32 @@ describe('rc-tooltip', () => { expect(container.querySelector('.x-content')).toBeTruthy(); }); + it('temporarily hides while disabled and restores without mouse leave', () => { + const App = () => { + const [disabled, setDisabled] = React.useState(false); + + return ( + + + + ); + }; + + const { container } = render(); + const button = container.querySelector('button'); + + fireEvent.mouseEnter(button); + expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden'); + + fireEvent.click(button); + expect(container.querySelector('.rc-tooltip')).toHaveClass('rc-tooltip-hidden'); + + fireEvent.click(button); + expect(container.querySelector('.rc-tooltip')).not.toHaveClass('rc-tooltip-hidden'); + }); + it('ref support nativeElement', () => { const nodeRef = React.createRef();