NervJS / taro-ui

一款基于 Taro 框架开发的多端 UI 组件库
https://taro-ui.taro.zone
MIT License
4.55k stars 756 forks source link

值为0或不存在时不展示角标 #1591

Closed name-q closed 1 year ago

name-q commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch taro-ui@3.0.0-alpha.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/taro-ui/dist/index.js b/node_modules/taro-ui/dist/index.js
index 8d62fcc..17422ca 100644
--- a/node_modules/taro-ui/dist/index.js
+++ b/node_modules/taro-ui/dist/index.js
@@ -1724,6 +1724,8 @@ var AtBadge = /** @class */ (function (_super) {
         var _a = this.props, dot = _a.dot, value = _a.value, _b = _a.maxValue, maxValue = _b === void 0 ? 99 : _b, customStyle = _a.customStyle;
         var rootClassName = ['at-badge'];
         var val = this.formatValue(value, maxValue);
+        // 值为0或不存在时不展示角标
+        if(!value) return this.props.children;
         return (React__default.createElement(components.View, { className: classnames(rootClassName, this.props.className), style: customStyle },
             this.props.children,
             dot ? (React__default.createElement(components.View, { className: 'at-badge__dot' })) : (val !== '' && React__default.createElement(components.View, { className: 'at-badge__num' }, val))));
diff --git a/node_modules/taro-ui/lib/components/badge/index.js b/node_modules/taro-ui/lib/components/badge/index.js
index b2c17a3..7247c69 100644
--- a/node_modules/taro-ui/lib/components/badge/index.js
+++ b/node_modules/taro-ui/lib/components/badge/index.js
@@ -20,6 +20,8 @@ export default class AtBadge extends React.Component {
         const { dot, value, maxValue = 99, customStyle } = this.props;
         const rootClassName = ['at-badge'];
         const val = this.formatValue(value, maxValue);
+        // 值为0或不存在时不展示角标
+        if(!value) return this.props.children;
         return (React.createElement(View, { className: classNames(rootClassName, this.props.className), style: customStyle },
             this.props.children,
             dot ? (React.createElement(View, { className: 'at-badge__dot' })) : (val !== '' && React.createElement(View, { className: 'at-badge__num' }, val))));
diff --git a/node_modules/taro-ui/types/accordion.d.ts b/node_modules/taro-ui/types/accordion.d.ts
index 5f9d819..947b7a3 100644
--- a/node_modules/taro-ui/types/accordion.d.ts
+++ b/node_modules/taro-ui/types/accordion.d.ts
@@ -12,7 +12,7 @@ export interface AtAccordionProps extends AtComponent {
   /**
    * 标题
    */
-  title?: string
+  title?: string | unknown
   /**
    * 图标,仅支持 AtIcon 支持的类型,
    * object 属性有 value color size prefixClass
diff --git a/node_modules/taro-ui/types/badge.d.ts b/node_modules/taro-ui/types/badge.d.ts
index 5ead8bd..6f646d1 100644
--- a/node_modules/taro-ui/types/badge.d.ts
+++ b/node_modules/taro-ui/types/badge.d.ts
@@ -17,6 +17,8 @@ export interface AtBadgeProps extends AtComponent {
    * @default 99
    */
   maxValue?: number
+
+  children?:any
 }

 declare const AtBadge: ComponentClass<AtBadgeProps>

This issue body was partially generated by patch-package.

taro-ui-bot[bot] commented 1 year ago

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~