fix(components): [button] space is not added (#6361)

This commit is contained in:
Alan Wang
2022-03-02 12:17:03 +08:00
committed by GitHub
parent 69de57b8d4
commit e95dedd22b
2 changed files with 17 additions and 2 deletions

View File

@@ -206,4 +206,19 @@ describe('Button Group', () => {
'el-button__text--expand'
)
})
it('add space between two Chinese characters even if there is whitespace at both ends', async () => {
const wrapper = mount(Button, {
slots: {
default: ' 中文 ',
},
props: {
autoInsertSpace: true,
},
})
expect(wrapper.find('.el-button span').text()).toBe('中文')
expect(wrapper.find('.el-button span').classes()).toContain(
'el-button__text--expand'
)
})
})

View File

@@ -77,8 +77,8 @@ const shouldAddSpace = computed(() => {
if (autoInsertSpace.value && defaultSlot?.length === 1) {
const slot = defaultSlot[0]
if (slot?.type === Text) {
const text = slot.children
return /^\p{Unified_Ideograph}{2}$/u.test(text as string)
const text = slot.children as string
return /^\p{Unified_Ideograph}{2}$/u.test(text.trim())
}
}
return false