Skip to content

Commit 630e29a

Browse files
committedMay 16, 2024·
feat(client): support slot props in AutoLink
1 parent 98d98db commit 630e29a

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed
 

‎e2e/docs/components/auto-link.md

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
<AutoLink download="example-test.png" :config="{ text: 'text3', link: 'https://example.com/test.png' }" />
2020
</div>
2121

22+
<div id="slots">
23+
<AutoLink :config="{ text: 'text1', link: '/', ariaLabel: 'label', icon: 'icon1' }">
24+
slot-text
25+
</AutoLink>
26+
<AutoLink :config="{ text: 'text2', link: '/', ariaLabel: 'label', icon: 'icon1' }">
27+
<template v-slot="{ ariaLabel }">{{ ariaLabel }}</template>
28+
</AutoLink>
29+
<AutoLink :config="{ text: 'text3', link: '/', ariaLabel: 'label', icon: 'icon1' }">
30+
<template #before>before</template>
31+
<template #after>after</template>
32+
</AutoLink>
33+
<AutoLink :config="{ text: 'text4', link: '/', ariaLabel: 'label', icon: 'icon1' }">
34+
<template #before="{ ariaLabel }">before {{ ariaLabel }}</template>
35+
<template #after="{ ariaLabel }">after {{ ariaLabel }}</template>
36+
</AutoLink>
37+
</div>
38+
2239
<script setup lang="ts">
2340
import { AutoLink } from 'vuepress/client'
2441

‎e2e/tests/components/auto-link.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,12 @@ test('should append attrs correctly', async ({ page }) => {
6565
await expect(locator.nth(2)).toHaveAttribute('rel', 'noopener noreferrer')
6666
await expect(locator.nth(2)).toHaveAttribute('download', 'example-test.png')
6767
})
68+
69+
test('should render slots correctly', async ({ page }) => {
70+
const locator = page.locator('.e2e-theme-content #slots a')
71+
72+
await expect(locator.nth(0)).toHaveText('slot-text')
73+
await expect(locator.nth(1)).toHaveText('label')
74+
await expect(locator.nth(2)).toHaveText('beforetext3after')
75+
await expect(locator.nth(3)).toHaveText('before labeltext4after label')
76+
})

‎packages/client/src/components/AutoLink.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export const AutoLink = defineComponent({
5959
},
6060

6161
slots: Object as SlotsType<{
62-
default?: () => VNode[] | VNode
63-
before?: () => VNode[] | VNode | null
64-
after?: () => VNode[] | VNode | null
62+
default?: (config: AutoLinkConfig) => VNode[] | VNode
63+
before?: (config: AutoLinkConfig) => VNode[] | VNode | null
64+
after?: (config: AutoLinkConfig) => VNode[] | VNode | null
6565
}>,
6666

6767
setup(props, { slots }) {
@@ -134,10 +134,10 @@ export const AutoLink = defineComponent({
134134
return () => {
135135
const { before, after, default: defaultSlot } = slots
136136

137-
const content = defaultSlot?.() || [
138-
before?.(),
137+
const content = defaultSlot?.(config.value) || [
138+
before?.(config.value),
139139
config.value.text,
140-
after?.(),
140+
after?.(config.value),
141141
]
142142

143143
return isInternal.value

0 commit comments

Comments
 (0)
Please sign in to comment.