mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-02 11:17:46 +08:00
fix(hooks): [use-namespace] exclude invalid CSS variables (#8905)
* fix(hooks): [use-namespace] exclude invalid CSS variables * test(hooks): [use-namespace] add test
This commit is contained in:
parent
ef90159db5
commit
c28e1cfa42
@ -7,6 +7,14 @@ import type { VueWrapper } from '@vue/test-utils'
|
||||
const TestComp = defineComponent({
|
||||
setup() {
|
||||
const ns = useNamespace('table')
|
||||
const cssVar = ns.cssVar({
|
||||
'border-style': 'solid',
|
||||
'border-width': '',
|
||||
})
|
||||
const cssVarBlock = ns.cssVarBlock({
|
||||
'text-color': '#409eff',
|
||||
'active-color': '',
|
||||
})
|
||||
return () => (
|
||||
<div
|
||||
id="testId"
|
||||
@ -27,6 +35,7 @@ const TestComp = defineComponent({
|
||||
ns.is('hover', undefined), // return empty string
|
||||
ns.is('clicked', false), // return empty string
|
||||
]}
|
||||
style={{ ...cssVar, ...cssVarBlock }}
|
||||
>
|
||||
text
|
||||
</div>
|
||||
@ -64,5 +73,11 @@ describe('use-locale', () => {
|
||||
'ep-table-body__content--active', // bem('body', 'content', 'active')
|
||||
'is-focus', // is('focus')
|
||||
])
|
||||
|
||||
const style = wrapper.find('#testId').attributes('style')
|
||||
expect(style).toMatch('--ep-border-style: solid;')
|
||||
expect(style).not.toMatch('--ep-border-width:')
|
||||
expect(style).toMatch('--ep-table-text-color: #409eff;')
|
||||
expect(style).not.toMatch('--ep-table-active-color:')
|
||||
})
|
||||
})
|
||||
|
@ -62,7 +62,9 @@ export const useNamespace = (block: string) => {
|
||||
const cssVar = (object: Record<string, string>) => {
|
||||
const styles: Record<string, string> = {}
|
||||
for (const key in object) {
|
||||
styles[`--${namespace.value}-${key}`] = object[key]
|
||||
if (object[key]) {
|
||||
styles[`--${namespace.value}-${key}`] = object[key]
|
||||
}
|
||||
}
|
||||
return styles
|
||||
}
|
||||
@ -70,7 +72,9 @@ export const useNamespace = (block: string) => {
|
||||
const cssVarBlock = (object: Record<string, string>) => {
|
||||
const styles: Record<string, string> = {}
|
||||
for (const key in object) {
|
||||
styles[`--${namespace.value}-${block}-${key}`] = object[key]
|
||||
if (object[key]) {
|
||||
styles[`--${namespace.value}-${block}-${key}`] = object[key]
|
||||
}
|
||||
}
|
||||
return styles
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user