Skip to content

Commit 410b297

Browse files
authored
fix(link): remove link's emits declare and add e2e test for click event (#1944)
1 parent d26c5a0 commit 410b297

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

examples/sites/demos/pc/app/link/basic-usage-composition-api.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<template>
22
<div>
3-
<tiny-link>默认链接</tiny-link>
3+
<tiny-link @click="handleClick">默认链接</tiny-link>
44
<tiny-link value="默认链接2"></tiny-link>
55
</div>
66
</template>
77

88
<script setup>
99
import { Link as TinyLink } from '@opentiny/vue'
10+
11+
function handleClick() {
12+
console.log('clicked')
13+
}
1014
</script>
1115

1216
<style scoped>

examples/sites/demos/pc/app/link/basic-usage.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ test('基础用法', async ({ page }) => {
1010
await expect(link.nth(1)).toHaveText('默认链接2')
1111
await link.first().hover()
1212
await expect(link.first()).toHaveCSS('color', 'rgb(82, 110, 204)')
13+
14+
// 测试点击
15+
const values = [] as string[]
16+
page.on('console', async (msg) => {
17+
for (const arg of msg.args()) {
18+
values.push(await arg.jsonValue())
19+
}
20+
})
21+
await link.first().click()
22+
23+
expect(values[0]).toBe('clicked')
1324
})

examples/sites/demos/pc/app/link/basic-usage.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<tiny-link>默认链接</tiny-link>
3+
<tiny-link @click="handleClick">默认链接</tiny-link>
44
<tiny-link value="默认链接2"></tiny-link>
55
</div>
66
</template>
@@ -11,6 +11,11 @@ import { Link } from '@opentiny/vue'
1111
export default {
1212
components: {
1313
TinyLink: Link
14+
},
15+
methods: {
16+
handleClick() {
17+
console.log('clicked')
18+
}
1419
}
1520
}
1621
</script>

examples/sites/demos/pc/app/link/webdoc/link.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ export default {
99
'en-US': 'Basic Usage'
1010
},
1111
desc: {
12-
'zh-CN': '<p>通过 <code>value</code> 或者默认插槽设置链接显示内容。</p>',
13-
'en-US': '<p>Set the link to display content via <code>value</code> or the default slot. </p></p>'
12+
'zh-CN': `
13+
通过 <code>value</code> 或者默认插槽设置链接显示内容。<br>
14+
绑定 <code>click</code> 事件监听点击。 当禁用或配置 <code>href</code> 属性时, 不会触发<code>click</code>事件!
15+
`,
16+
'en-US': `
17+
Set the link to display content via <code>value</code> or the default slot.
18+
Bind the click event to listen for clicks.The click event is not triggered when the href attribute is disabled or configured!
19+
`
1420
},
1521
codeFiles: ['basic-usage.vue']
1622
},

packages/vue/src/link/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{
22
"name": "@opentiny/vue-link",
3-
"version": "3.18.0",
3+
"type": "module",
4+
"version": "3.18.1",
45
"description": "",
6+
"license": "MIT",
7+
"sideEffects": false,
58
"main": "lib/index.js",
69
"module": "index.ts",
7-
"sideEffects": false,
8-
"type": "module",
9-
"devDependencies": {
10-
"@opentiny-internal/vue-test-utils": "workspace:*",
11-
"vitest": "^0.31.0"
12-
},
1310
"scripts": {
1411
"build": "pnpm -w build:ui $npm_package_name",
1512
"//postversion": "pnpm build"
@@ -19,5 +16,8 @@
1916
"@opentiny/vue-renderless": "workspace:~",
2017
"@opentiny/vue-theme": "workspace:~"
2118
},
22-
"license": "MIT"
23-
}
19+
"devDependencies": {
20+
"@opentiny-internal/vue-test-utils": "workspace:*",
21+
"vitest": "^0.31.0"
22+
}
23+
}

packages/vue/src/link/src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ export const linkProps = {
3737
export default defineComponent({
3838
name: $prefix + 'Link',
3939
props: linkProps,
40-
emits: {
41-
click(_ev: MouseEvent) {
42-
return true
43-
}
44-
},
45-
slots: Object as SlotsType<{
46-
/** 默认插槽 */
47-
default: {}
48-
/** 图标插槽 */
49-
icon: {}
50-
}>,
5140
setup(props, context) {
5241
return $setup({ props, context, template })
5342
}

0 commit comments

Comments
 (0)