Skip to content

Commit

Permalink
feat(tag): add content-style prop
Browse files Browse the repository at this point in the history
  • Loading branch information
kungege committed Nov 26, 2024
1 parent 492d2e3 commit 169ae10
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## NEXT_VERSION

`xxxx-xx-xx`

### Fixes

### Features

- `n-tag` adds `content-style` prop.

## 2.40.2

`2025-11-26`
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## NEXT_VERSION

`xxxx-xx-xx`

### Fixes

### Features

- `n-tag` 新增 `content-style` 属性

## 2.40.2

`2025-11-26`
Expand Down
1 change: 1 addition & 0 deletions src/tag/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ icon.vue
| checked | `boolean` | `false` | Whether the tag is checked. Note: used with `checkable`. | |
| closable | `boolean` | `false` | Whether the tag shows a close button. | |
| color | `{ color?: string, borderColor?: string, textColor?: string }` | `undefined` | Color of the tag. Note: this will override the type property's color. | |
| content-style | `string \| Object` | `undefined` | Content style of the tag. | NEXT-VERSION |
| disabled | `boolean` | `false` | Whether the tag is disabled. | |
| round | `boolean` | `false` | Whether the tag has rounded corners. | |
| size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size of the tag. | |
Expand Down
1 change: 1 addition & 0 deletions src/tag/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rtl-debug.vue
| checked | `boolean` | `false` | 是否被选中,配合 checkable 一起使用 | |
| closable | `boolean` | `false` | 是否可关闭 | |
| color | `{ color?: string, borderColor?: string, textColor?: string }` | `undefined` | 标签颜色,设置该项后 `type` 无效 | |
| content-style | `string \| Object` | `undefined` | tag 内容的样式 | NEXT_VERSION |
| disabled | `boolean` | `false` | 是否禁用 | |
| round | `boolean` | `false` | 是否圆角 | |
| size | `'small' \| 'medium' \| 'large'` | `'medium'` | 尺寸 | |
Expand Down
8 changes: 7 additions & 1 deletion src/tag/src/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const tagProps = {
},
checked: Boolean,
checkable: Boolean,
contentStyle: [Object, String] as PropType<CSSProperties | string>,
strong: Boolean,
triggerClickOnClose: Boolean,
onClose: [Array, Function] as PropType<MaybeArray<(e: MouseEvent) => void>>,
Expand Down Expand Up @@ -259,6 +260,7 @@ export default defineComponent({
rtlEnabled,
closable,
color: { borderColor } = {},
contentStyle,
round,
onRender,
$slots
Expand Down Expand Up @@ -299,7 +301,11 @@ export default defineComponent({
onMouseleave={this.onMouseleave}
>
{iconNode || avatarNode}
<span class={`${mergedClsPrefix}-tag__content`} ref="contentRef">
<span
class={`${mergedClsPrefix}-tag__content`}
ref="contentRef"
style={contentStyle}
>
{this.$slots.default?.()}
</span>
{!this.checkable && closable ? (
Expand Down
13 changes: 13 additions & 0 deletions src/tag/tests/Tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,17 @@ describe('n-tag', () => {
'--n-merged-size: var(--n-avatar-size-override, 34px);'
)
})

it('should work with `content-style` prop', () => {
const wrapper = mount(NTag, {
props: {
contentStyle: {
color: 'rgb(204, 204, 204)'
}
}
})
expect(wrapper.find('.n-tag__content').attributes('style')).toContain(
'color: rgb(204, 204, 204);'
)
})
})

0 comments on commit 169ae10

Please sign in to comment.