diff --git a/components/button/button-helper.tsx b/components/button/button-helper.tsx
index 2107f40..92f51bd 100644
--- a/components/button/button-helper.tsx
+++ b/components/button/button-helper.tsx
@@ -1,6 +1,7 @@
// import type { VNode, VNodeChild } from 'vue'
// import { isString } from '@v-c/utils'
-// import { cloneVNode } from 'vue'
+import { Text } from 'vue'
+import type { VNode } from 'vue'
const rxTwoCNChar = /^[\u4E00-\u9FA5]{2}$/
export const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar)
@@ -8,6 +9,18 @@ export const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar)
export function isUnBorderedButtonType(type?: ButtonType) {
return type === 'text' || type === 'link'
}
+export const spaceChildren = (child: VNode, needInserted: boolean) => {
+ const SPACE = needInserted ? ' ' : ''
+ if (child.type === Text) {
+ let text = (child.children as string).trim()
+ if (isTwoCNChar(text)) {
+ text = text.split('').join(SPACE)
+ }
+ return {text}
+ }
+ return child
+}
+
//
// function splitCNCharsBySpace(child: VNodeChild , needInserted: boolean) {
// if (child === null || child === undefined) {
diff --git a/components/button/button.tsx b/components/button/button.tsx
index 660b693..854e2fb 100644
--- a/components/button/button.tsx
+++ b/components/button/button.tsx
@@ -16,7 +16,11 @@ import { useCompactItemContext } from '../space/compact'
import useStyle from './style'
import type { ButtonProps, LoadingConfigType } from './interface'
import { buttonProps } from './interface'
-import { isTwoCNChar, isUnBorderedButtonType } from './button-helper'
+import {
+ isTwoCNChar,
+ isUnBorderedButtonType,
+ spaceChildren
+} from './button-helper'
type Loading = number | boolean
function getLoadingConfig(loading: ButtonProps['loading']): LoadingConfigType {
@@ -181,6 +185,10 @@ const Button = defineComponent({
)
const iconNode = icon && (!innerLoading.value ? icon?.() : <>L>)
+ const kids =
+ children || children === 0
+ ? spaceChildren(children[0] as any, isNeedInserted && autoInsertSpace)
+ : undefined
if (attrs.href !== undefined) {
return wrapSSR(
{iconNode}
- {children}
+ {kids}
)
}
@@ -203,7 +211,7 @@ const Button = defineComponent({
ref={buttonRef}
>
{iconNode}
- {children}
+ {kids}
)