Skip to content

feat(float-button): support TooltipProps#53138

Merged
zombieJ merged 10 commits intoant-design:featurefrom
Wxh16144-forks:wuxh/feat-52998
Mar 13, 2025
Merged

feat(float-button): support TooltipProps#53138
zombieJ merged 10 commits intoant-design:featurefrom
Wxh16144-forks:wuxh/feat-52998

Conversation

@Wxh16144
Copy link
Copy Markdown
Member

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

fix #52998

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English <FloatButton /> supports tooltip props
🇨🇳 Chinese ` 支持 tooltip props

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 12, 2025

👁 Visual Regression Report for PR #53138 Passed ✅

🎯 Target branch: feature (af84ba5)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 12, 2025

Preview is ready

@petercat-assistant
Copy link
Copy Markdown

Walkthrough

This pull request introduces a new feature to the <FloatButton /> component, enabling it to support TooltipProps. The changes include the addition of a utility function to convert tooltip data into TooltipProps, updates to the FloatButton component to utilize this function, and modifications to tests and documentation to reflect the new functionality.

Changes

Files Summary
components/_util/convertToTooltipProps.ts Added a utility function to convert tooltip data into TooltipProps.
components/float-button/FloatButton.tsx Updated to support TooltipProps for tooltips, including special handling for numeric tooltips.
components/float-button/tests/index.test.tsx Enhanced tests to cover new tooltip functionality and warnings.
components/float-button/demo/tooltip.tsx Updated demo to showcase new tooltip functionality.
components/float-button/index.en-US.md, components/float-button/index.zh-CN.md Updated documentation to include TooltipProps support.
components/float-button/interface.ts Modified interface to accept TooltipProps for tooltips.
components/form/FormItemLabel.tsx Replaced existing tooltip conversion logic with the new utility function.

Comment thread components/float-button/FloatButton.tsx Outdated
warning(
false,
'usage',
'The `tooltip` value is `0`(number). If you want to show `0`, please use string `"0"` instead.',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message for tooltip value being 0 is a good addition to prevent potential confusion. However, ensure that this warning does not interfere with other functionalities or cause unnecessary noise in the console.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 12, 2025

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 12, 2025

Bundle Report

Changes will increase total bundle size by 14 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.38MB 14 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.min.js 7 bytes 1.84MB 0.0%
antd.min.js 7 bytes 1.54MB 0.0%

Comment on lines -87 to +109
if ('tooltip' in props) {
buttonNode = (
<Tooltip title={tooltip} placement={direction === 'rtl' ? 'right' : 'left'}>
{buttonNode}
</Tooltip>
);
// ============================ Tooltip ============================
let tooltipProps: TooltipProps | null = null;
/**
* 理论上直接 `const tooltipProps = convertToTooltipProps(tooltip);` 即可。同 Form.Item 的 tooltip 逻辑。
* 但在 https://github.com/ant-design/ant-design/pull/39425 存在 tooltip 为 0 的 unit test,所以这里做了特殊处理。
*/
if (tooltip === 0) {
tooltipProps = { title: tooltip };
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning('FloatButton');
warning(
false,
'usage',
'The `tooltip` value is `0`(number). If you want to show `0`, please use string `"0"` instead.',
);
}
} else {
tooltipProps = convertToTooltipProps(tooltip);
}

if (tooltipProps) {
buttonNode = <Tooltip {...tooltipProps}>{buttonNode}</Tooltip>;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是第一版逻辑

   if ('tooltip' in props) {
-    buttonNode = (
-      <Tooltip title={tooltip} placement={direction === 'rtl' ? 'right' : 'left'}>
-        {buttonNode}
-      </Tooltip>
-    );
+    let tooltipProps: TooltipProps = {
+      placement: direction === 'rtl' ? 'right' : 'left',
+    };
+
+    if (typeof tooltip === 'object' && tooltip !== null) {
+      if (isValidElement(tooltip)) {
+        tooltipProps.title = tooltip;
+      } else {
+        tooltipProps = { ...tooltipProps, ...tooltip };
+      }
+    } else if (tooltip !== undefined) {
+      tooltipProps.title = tooltip;
+    }
+
+    buttonNode = <Tooltip {...tooltipProps}>{buttonNode}</Tooltip>;
   }

后面想了一下 Form.Item 也有类似的处理,想着复用一下。 但是 #39425 有一个 number 0 的 unit test case。

所以,这里啰嗦了一句,给开发者一个 usage warin,然后在 v7 可以考虑删除 number 0 的 case。

Comment thread components/float-button/FloatButton.tsx Outdated
warning(
false,
'usage',
'The `tooltip` value is `0`(number). If you want to show `0`, please use string `"0"` instead.',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 和其他数字没有区别,没有必要对其进行特殊处理。

Copy link
Copy Markdown
Member Author

@Wxh16144 Wxh16144 Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!0 === true ,其他数字不会

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (af84ba5) to head (16b267e).
Report is 1 commits behind head on feature.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #53138   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          769       770    +1     
  Lines        13880     13880           
  Branches      3640      3639    -1     
=========================================
  Hits         13880     13880           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zombieJ zombieJ merged commit d38aea0 into ant-design:feature Mar 13, 2025
This was referenced May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants