diff --git a/components/badge/__tests__/__snapshots__/index.test.js.snap b/components/badge/__tests__/__snapshots__/index.test.js.snap index a58afd99ee..0857e9ce9c 100644 --- a/components/badge/__tests__/__snapshots__/index.test.js.snap +++ b/components/badge/__tests__/__snapshots__/index.test.js.snap @@ -69,6 +69,42 @@ exports[`Badge badge should support float number 2`] = ` `; +exports[`Badge render Badge status/color when contains children 1`] = ` +Array [ + + + + , + + + + , + + + + , +] +`; + exports[`Badge render correct with negative number 1`] = `
{ ); expect(wrapper).toMatchSnapshot(); }); + + // https://github.com/ant-design/ant-design/issues/21331 + it('render Badge status/color when contains children', () => { + const wrapper = render( + <> + + + + + + + + + + , + ); + expect(wrapper).toMatchSnapshot(); + }) }); diff --git a/components/badge/index.tsx b/components/badge/index.tsx index 728380b5d5..fe7e68b9de 100644 --- a/components/badge/index.tsx +++ b/components/badge/index.tsx @@ -129,7 +129,7 @@ export default class Badge extends React.Component { } renderBadgeNumber(prefixCls: string, scrollNumberPrefixCls: string) { - const { status, count } = this.props; + const { status, count, color } = this.props; const displayCount = this.getDisplayCount(); const isDot = this.isDot(); @@ -140,9 +140,16 @@ export default class Badge extends React.Component { [`${prefixCls}-count`]: !isDot, [`${prefixCls}-multiple-words`]: !isDot && count && count.toString && count.toString().length > 1, - [`${prefixCls}-status-${status}`]: this.hasStatus(), + [`${prefixCls}-status-${status}`]: !!status, + [`${prefixCls}-status-${color}`]: isPresetColor(color), }); + let statusStyle: React.CSSProperties | undefined = this.getStyleWithOffset(); + if (color && !isPresetColor(color)) { + statusStyle = statusStyle || {}; + statusStyle.background = color; + } + return hidden ? null : ( { count={displayCount} displayComponent={this.renderDisplayComponent()} // }> title={this.getScrollNumberTitle()} - style={this.getStyleWithOffset()} + style={statusStyle} key="scrollNumber" /> );