mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
feat: add statusTitle
prop to Badge component
This commit is contained in:
parent
390e346141
commit
94735bc53d
@ -262,4 +262,20 @@ describe('Badge', () => {
|
|||||||
expect(element).toHaveStyle({ backgroundColor: 'yellow' });
|
expect(element).toHaveStyle({ backgroundColor: 'yellow' });
|
||||||
expect(element?.querySelector<HTMLElement>('sup')).toHaveStyle({ backgroundColor: 'blue' });
|
expect(element?.querySelector<HTMLElement>('sup')).toHaveStyle({ backgroundColor: 'blue' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should display custom status title when statusTitle is set', () => {
|
||||||
|
const { container } = render(<Badge status="success" statusTitle="Custom Status Title" />);
|
||||||
|
const badgeStatusElement = container.querySelector('.ant-badge-status-text');
|
||||||
|
|
||||||
|
expect(badgeStatusElement).toBeTruthy();
|
||||||
|
expect(badgeStatusElement?.getAttribute('title')).toBe('Custom Status Title');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback to default title when statusTitle is not set', () => {
|
||||||
|
const { container } = render(<Badge status="success" />);
|
||||||
|
const badgeStatusElement = container.querySelector('.ant-badge-status-text');
|
||||||
|
|
||||||
|
expect(badgeStatusElement).toBeTruthy();
|
||||||
|
expect(badgeStatusElement?.getAttribute('title')).toBe(null); // 默认无title,若有则根据情况修改
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -50,6 +50,7 @@ Common props ref:[Common props](/docs/react/common-props)
|
|||||||
| showZero | Whether to show badge when `count` is zero | boolean | false | |
|
| showZero | Whether to show badge when `count` is zero | boolean | false | |
|
||||||
| size | If `count` is set, `size` sets the size of badge | `default` \| `small` | - | - |
|
| size | If `count` is set, `size` sets the size of badge | `default` \| `small` | - | - |
|
||||||
| status | Set Badge as a status dot | `success` \| `processing` \| `default` \| `error` \| `warning` | - | |
|
| status | Set Badge as a status dot | `success` \| `processing` \| `default` \| `error` \| `warning` | - | |
|
||||||
|
| statusTitle | Sets the text displayed when hovering over the status dot. Effective only when status is set. | string | - |
|
||||||
| styles | Semantic DOM style | [Record<SemanticDOM, CSSProperties>](#semantic-dom) | - | 5.7.0 |
|
| styles | Semantic DOM style | [Record<SemanticDOM, CSSProperties>](#semantic-dom) | - | 5.7.0 |
|
||||||
| text | If `status` is set, `text` sets the display text of the status `dot` | ReactNode | - | |
|
| text | If `status` is set, `text` sets the display text of the status `dot` | ReactNode | - | |
|
||||||
| title | Text to show when hovering over the badge | string | - | |
|
| title | Text to show when hovering over the badge | string | - | |
|
||||||
|
@ -29,6 +29,7 @@ export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|||||||
className?: string;
|
className?: string;
|
||||||
rootClassName?: string;
|
rootClassName?: string;
|
||||||
status?: PresetStatusColorType;
|
status?: PresetStatusColorType;
|
||||||
|
statusTitle?: string;
|
||||||
color?: LiteralUnion<PresetColorKey>;
|
color?: LiteralUnion<PresetColorKey>;
|
||||||
text?: React.ReactNode;
|
text?: React.ReactNode;
|
||||||
size?: 'default' | 'small';
|
size?: 'default' | 'small';
|
||||||
@ -56,6 +57,7 @@ const InternalBadge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref)
|
|||||||
count = null,
|
count = null,
|
||||||
overflowCount = 99,
|
overflowCount = 99,
|
||||||
dot = false,
|
dot = false,
|
||||||
|
statusTitle,
|
||||||
size = 'default',
|
size = 'default',
|
||||||
title,
|
title,
|
||||||
offset,
|
offset,
|
||||||
@ -135,7 +137,6 @@ const InternalBadge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref)
|
|||||||
const titleNode =
|
const titleNode =
|
||||||
title ??
|
title ??
|
||||||
(typeof livingCount === 'string' || typeof livingCount === 'number' ? livingCount : undefined);
|
(typeof livingCount === 'string' || typeof livingCount === 'number' ? livingCount : undefined);
|
||||||
|
|
||||||
// >>> Status Text
|
// >>> Status Text
|
||||||
const statusTextNode =
|
const statusTextNode =
|
||||||
isHidden || !text ? null : <span className={`${prefixCls}-status-text`}>{text}</span>;
|
isHidden || !text ? null : <span className={`${prefixCls}-status-text`}>{text}</span>;
|
||||||
@ -190,6 +191,7 @@ const InternalBadge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref)
|
|||||||
style={{ ...styles?.root, ...badge?.styles?.root, ...mergedStyle }}
|
style={{ ...styles?.root, ...badge?.styles?.root, ...mergedStyle }}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
|
title={statusTitle}
|
||||||
className={statusCls}
|
className={statusCls}
|
||||||
style={{ ...styles?.indicator, ...badge?.styles?.indicator, ...statusStyle }}
|
style={{ ...styles?.indicator, ...badge?.styles?.indicator, ...statusStyle }}
|
||||||
/>
|
/>
|
||||||
|
@ -51,6 +51,7 @@ group: 数据展示
|
|||||||
| showZero | 当数值为 0 时,是否展示 Badge | boolean | false | |
|
| showZero | 当数值为 0 时,是否展示 Badge | boolean | false | |
|
||||||
| size | 在设置了 `count` 的前提下有效,设置小圆点的大小 | `default` \| `small` | - | - |
|
| size | 在设置了 `count` 的前提下有效,设置小圆点的大小 | `default` \| `small` | - | - |
|
||||||
| status | 设置 Badge 为状态点 | `success` \| `processing` \| `default` \| `error` \| `warning` | - | |
|
| status | 设置 Badge 为状态点 | `success` \| `processing` \| `default` \| `error` \| `warning` | - | |
|
||||||
|
| statusTitle | 设置鼠标放在status状态点的文本,在设置了 `status`的前提下有效。 | string | - | |
|
||||||
| styles | 语义化结构 style | [Record<SemanticDOM, CSSProperties>](#semantic-dom) | - | 5.7.0 |
|
| styles | 语义化结构 style | [Record<SemanticDOM, CSSProperties>](#semantic-dom) | - | 5.7.0 |
|
||||||
| text | 在设置了 `status` 的前提下有效,设置状态点的文本 | ReactNode | - | |
|
| text | 在设置了 `status` 的前提下有效,设置状态点的文本 | ReactNode | - | |
|
||||||
| title | 设置鼠标放在状态点上时显示的文字 | string | - | |
|
| title | 设置鼠标放在状态点上时显示的文字 | string | - | |
|
||||||
|
Loading…
Reference in New Issue
Block a user