Skip to content

Commit ec514f5

Browse files
licdreamFeng
authored andcommitted
Tag: add click event (ElemeFE#14106)
* Tag: add tag click event handle * Tag: add doc and unit test.
1 parent 7efcc1d commit ec514f5

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

examples/docs/en-US/tag.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,5 @@ Besides default size, Tag component provides three additional sizes for you to c
212212
### Events
213213
| Event Name | Description | Parameters |
214214
|---------- |-------- |---------- |
215+
| click | triggers when Tag is clicked ||
215216
| close | triggers when Tag is removed ||

examples/docs/es/tag.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,5 @@ Además del tamaño predeterminado, el componente Tag proporciona tres tamaños
212212
### Eventos
213213
| Nombre | Descripción | Parametros |
214214
| ------ | ------------------------------------ | ---------- |
215+
| click | se disoara cuando el Tag es clic ||
215216
| close | se disoara cuando el Tag es removido ||

examples/docs/zh-CN/tag.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,5 @@ Tag 组件提供除了默认值以外的三种尺寸,可以在不同场景下
212212
### Events
213213
| 事件名称 | 说明 | 回调参数 |
214214
|---------- |-------- |---------- |
215-
| close | 关闭 Tag 时触发的事件 ||
215+
| click | 点击 Tag 时触发的事件 ||
216+
| close | 关闭 Tag 时触发的事件 ||

packages/tag/src/tag.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
handleClose(event) {
1515
event.stopPropagation();
1616
this.$emit('close', event);
17+
},
18+
handleClick(event) {
19+
event.stopPropagation();
20+
this.$emit('click', event);
1721
}
1822
},
1923
computed: {
@@ -26,7 +30,7 @@
2630
this.tagSize ? `el-tag--${this.tagSize}` : '',
2731
{'is-hit': this.hit}
2832
];
29-
const tagEl = (<span class={classes} style={{backgroundColor: this.color}}>
33+
const tagEl = (<span class={classes} style={{backgroundColor: this.color}} on-click={this.handleClick}>
3034
{ this.$slots.default }
3135
{
3236
this.closable && <i class="el-tag__close el-icon-close" on-click={this.handleClose}></i>

test/unit/specs/tag.spec.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,35 @@ describe('Tag', () => {
8282
it('color', () => {
8383
vm = createVue({
8484
template: `
85-
<el-tag color="rgb(0, 0, 0)"></el-tag>
85+
<el-tag ref="tag" color="rgb(0, 0, 0)"></el-tag>
8686
`
8787
}, true);
8888
expect(vm.$el.style.backgroundColor).to.equal('rgb(0, 0, 0)');
8989
});
90+
91+
it('click', done => {
92+
vm = createVue({
93+
template: `
94+
<el-tag ref="tag" @click="handleClick">点击标签</el-tag>
95+
`,
96+
data() {
97+
return {
98+
clicksCount: 0
99+
};
100+
},
101+
methods: {
102+
handleClick() {
103+
this.clicksCount = this.clicksCount + 1;
104+
}
105+
}
106+
}, true);
107+
108+
let tag = vm.$refs.tag;
109+
tag.$el.click();
110+
111+
setTimeout(_ => {
112+
expect(vm.clicksCount).to.be.equal(1);
113+
done();
114+
}, 20);
115+
});
90116
});

0 commit comments

Comments
 (0)