From 1fe61205144f279e6610603fc2298bfd016aabb0 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Sun, 11 Feb 2024 22:21:20 +0800 Subject: [PATCH] feat: allow `Text` as `VClick`'s top-level child (#1214) (#1285) --- packages/client/builtin/VClick.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/client/builtin/VClick.ts b/packages/client/builtin/VClick.ts index 90548581ee..0535f11b44 100644 --- a/packages/client/builtin/VClick.ts +++ b/packages/client/builtin/VClick.ts @@ -4,7 +4,8 @@ * Learn more: https://sli.dev/guide/animations.html#click-animations */ -import { createVNode, defineComponent } from 'vue' +import type { PropType, VNode } from 'vue' +import { Text, defineComponent, h } from 'vue' import VClicks from './VClicks' export default defineComponent({ @@ -21,9 +22,13 @@ export default defineComponent({ type: Boolean, default: false, }, + wrapText: { + type: Function as PropType<(text: VNode) => VNode>, + default: (text: VNode) => h('span', text), + }, }, render() { - return createVNode( + return h( VClicks, { every: 99999, @@ -31,7 +36,14 @@ export default defineComponent({ hide: this.hide, fade: this.fade, }, - { default: this.$slots.default }, + { + default: () => + this.$slots.default?.().map(v => + v.type === Text + ? this.wrapText(v) + : v, + ), + }, ) }, })