Skip to content

Commit

Permalink
Merge pull request #2617 from aqiusen/hotfix/badge(#2616)
Browse files Browse the repository at this point in the history
fix(badge): #2616
  • Loading branch information
solarjoker authored Oct 10, 2023
2 parents c62c422 + 9b535e2 commit 9174d39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/ui/badge/src/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useMemo, isValidElement, cloneElement } from 'react'
import React, { forwardRef, useMemo, isValidElement, cloneElement, ReactNode } from 'react'
import { cx, getPrefixCls } from '@hi-ui/classname'
import { __DEV__, invariant } from '@hi-ui/env'
import { HiBaseHTMLProps } from '@hi-ui/core'
Expand All @@ -7,6 +7,11 @@ import { BadgeTypeEnum } from './types'

const _prefix = getPrefixCls('badge')

// 支持字符串和 number hover 显示,其他过滤
const getShowContent = (content: ReactNode) => {
if (!['number', 'string'].includes(typeof content)) return ""
return `${content}`
}
/**
* 红点 / 徽标
*
Expand Down Expand Up @@ -78,13 +83,13 @@ export const Badge = forwardRef<HTMLSpanElement | null, BadgeProps>(
})
}

return <span className={`${prefixCls}__value`} style={badgeStyle} children={count} />
return <span className={`${prefixCls}__value`} style={badgeStyle} title={getShowContent(content)} children={count} />
}, [type, prefixCls, badgeStyle, count])

const cls = cx(prefixCls, className, isNullish(children) && `${prefixCls}--independent`)

return (
<span ref={ref} className={cls} style={style} title={count as string} {...rest}>
<span ref={ref} className={cls} style={style} {...rest}>
{children}
{visible ? badgeNode : null}
</span>
Expand Down
1 change: 0 additions & 1 deletion packages/ui/badge/stories/color.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const Color = () => {
'magenta',
'#2db7f5',
'#108ee9',
'#2db7f5',
]

return (
Expand Down

0 comments on commit 9174d39

Please sign in to comment.