Skip to content

Commit 1fe6120

Browse files
authored
feat: allow Text as VClick's top-level child (#1214) (#1285)
1 parent b9d29f9 commit 1fe6120

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/client/builtin/VClick.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* Learn more: https://sli.dev/guide/animations.html#click-animations
55
*/
66

7-
import { createVNode, defineComponent } from 'vue'
7+
import type { PropType, VNode } from 'vue'
8+
import { Text, defineComponent, h } from 'vue'
89
import VClicks from './VClicks'
910

1011
export default defineComponent({
@@ -21,17 +22,28 @@ export default defineComponent({
2122
type: Boolean,
2223
default: false,
2324
},
25+
wrapText: {
26+
type: Function as PropType<(text: VNode) => VNode>,
27+
default: (text: VNode) => h('span', text),
28+
},
2429
},
2530
render() {
26-
return createVNode(
31+
return h(
2732
VClicks,
2833
{
2934
every: 99999,
3035
at: this.at,
3136
hide: this.hide,
3237
fade: this.fade,
3338
},
34-
{ default: this.$slots.default },
39+
{
40+
default: () =>
41+
this.$slots.default?.().map(v =>
42+
v.type === Text
43+
? this.wrapText(v)
44+
: v,
45+
),
46+
},
3547
)
3648
},
3749
})

0 commit comments

Comments
 (0)