From 5a78cb06a82f12eb6617ba42be1fd44402b6b67c Mon Sep 17 00:00:00 2001 From: "liaojinhao.ljh" Date: Thu, 16 Jul 2026 14:22:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(Actions):=20=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=AF=8F=E4=B8=AA=E6=93=8D=E4=BD=9C=E9=A1=B9?= =?UTF-8?q?=E7=9A=84=20Tooltip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/x/components/actions/ActionsItem.tsx | 17 +- packages/x/components/actions/Item.tsx | 15 +- .../__snapshots__/demo-extend.test.ts.snap | 200 +++++++++++++++--- .../__tests__/__snapshots__/demo.test.ts.snap | 92 ++++++++ .../actions/__tests__/action-item.test.tsx | 45 +++- .../actions/__tests__/index.test.tsx | 98 ++++++++- packages/x/components/actions/demo/tooltip.md | 7 + .../x/components/actions/demo/tooltip.tsx | 39 ++++ packages/x/components/actions/index.en-US.md | 3 + packages/x/components/actions/index.zh-CN.md | 15 +- packages/x/components/actions/interface.ts | 7 +- 11 files changed, 493 insertions(+), 45 deletions(-) create mode 100644 packages/x/components/actions/demo/tooltip.md create mode 100644 packages/x/components/actions/demo/tooltip.tsx diff --git a/packages/x/components/actions/ActionsItem.tsx b/packages/x/components/actions/ActionsItem.tsx index afa492d5eb..0ae4ec4362 100644 --- a/packages/x/components/actions/ActionsItem.tsx +++ b/packages/x/components/actions/ActionsItem.tsx @@ -1,6 +1,6 @@ import { CloseCircleOutlined, LoadingOutlined } from '@ant-design/icons'; import pickAttrs from '@rc-component/util/lib/pickAttrs'; -import { Tooltip } from 'antd'; +import { Tooltip, type TooltipProps } from 'antd'; import { clsx } from 'clsx'; import React from 'react'; import useMobile from '../_util/hooks/use-mobile'; @@ -69,6 +69,11 @@ export interface ActionsItemProps extends Omit>; + /** + * @desc 自定义操作项的 Tooltip,设为 false 时不渲染 Tooltip + * @descEN Tooltip for the action item, set to false to disable Tooltip + */ + tooltip?: string | TooltipProps | false; } const ActionsItem: React.FC = (props) => { @@ -77,6 +82,7 @@ const ActionsItem: React.FC = (props) => { defaultIcon, runningIcon, label, + tooltip, className, classNames = {}, styles = {}, @@ -138,7 +144,14 @@ const ActionsItem: React.FC = (props) => { ); - return isMobile ? innerNode : {innerNode}; + // ============================ Tooltip ============================ + const tooltipEnabled = tooltip !== false; + const tooltipProps: TooltipProps = + typeof tooltip === 'string' + ? { title: tooltip } + : (tooltip as TooltipProps) || { title: label }; + + return isMobile || !tooltipEnabled ? innerNode : {innerNode}; }; export default ActionsItem; diff --git a/packages/x/components/actions/Item.tsx b/packages/x/components/actions/Item.tsx index 287803c0b7..2bc3cf85fd 100644 --- a/packages/x/components/actions/Item.tsx +++ b/packages/x/components/actions/Item.tsx @@ -1,4 +1,4 @@ -import { Tooltip } from 'antd'; +import { Tooltip, type TooltipProps } from 'antd'; import { clsx } from 'clsx'; import React from 'react'; import useMobile from '../_util/hooks/use-mobile'; @@ -30,6 +30,17 @@ const Item: React.FC = (props) => { const iconElement =
{item?.icon}
; + // ============================ Tooltip ============================ + const tooltipConfig = item.tooltip; + const tooltipEnabled = tooltipConfig !== false; + const tooltipProps: TooltipProps = + typeof tooltipConfig === 'string' + ? { title: tooltipConfig } + : (tooltipConfig as TooltipProps) || { title: item.label }; + + const wrappedIcon = + isMobile || !tooltipEnabled ? iconElement : {iconElement}; + return (
= (props) => { }} key={itemKey} > - {isMobile ? iconElement : {iconElement}} + {wrappedIcon}
); }; diff --git a/packages/x/components/actions/__tests__/__snapshots__/demo-extend.test.ts.snap b/packages/x/components/actions/__tests__/__snapshots__/demo-extend.test.ts.snap index eda4ae3c6e..207aedf67b 100644 --- a/packages/x/components/actions/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/packages/x/components/actions/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -2,7 +2,7 @@ exports[`renders components/actions/demo/basic.tsx extend context correctly 1`] = `