This commit is contained in:
linzhe 2025-05-05 20:38:32 +00:00 committed by GitHub
commit fd08155354
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -79,6 +79,32 @@ describe(`runtime-dom: style patching`, () => {
expect(el.style.width).toBe('0px')
})
it('multiple patch with boolean style value', () => {
const el = document.createElement('div')
const styleA = {
left: 0,
right: true,
top: 0,
bottom: true,
}
patchProp(el as any, 'style', null, styleA)
expect(el.style.left).toBe('0px')
expect(el.style.right).toBe('')
expect(el.style.top).toBe('0px')
expect(el.style.bottom).toBe('')
const styleB = {
left: true,
right: 0,
top: true,
bottom: 0,
}
patchProp(el as any, 'style', styleA, styleB)
expect(el.style.left).toBe('')
expect(el.style.right).toBe('0px')
expect(el.style.top).toBe('')
expect(el.style.bottom).toBe('0px')
})
it('should remove style attribute on falsy value', () => {
const el = document.createElement('div')
el.style.cssText = 'color: red;'

View File

@ -75,7 +75,7 @@ function setStyle(
if (isArray(val)) {
val.forEach(v => setStyle(style, name, v))
} else {
if (val == null) val = ''
if (typeof val === 'boolean' || val == null) val = ''
if (__DEV__) {
if (semicolonRE.test(val)) {
warn(