chore: update

This commit is contained in:
linzhe141 2024-11-13 13:32:36 +08:00
parent 58464f2364
commit 7a91330d4f
2 changed files with 8 additions and 8 deletions

View File

@ -79,13 +79,13 @@ describe(`runtime-dom: style patching`, () => {
expect(el.style.width).toBe('0px')
})
it('multiple patch with falsy style value', () => {
it('multiple patch with boolean style value', () => {
const el = document.createElement('div')
const styleA = {
left: 0,
right: false,
right: true,
top: 0,
bottom: false,
bottom: true,
}
patchProp(el as any, 'style', null, styleA)
expect(el.style.left).toBe('0px')
@ -93,9 +93,9 @@ describe(`runtime-dom: style patching`, () => {
expect(el.style.top).toBe('0px')
expect(el.style.bottom).toBe('')
const styleB = {
left: false,
left: true,
right: 0,
top: false,
top: true,
bottom: 0,
}
patchProp(el as any, 'style', styleA, styleB)

View File

@ -19,14 +19,14 @@ export function patchStyle(el: Element, prev: Style, next: Style): void {
if (prev) {
if (!isString(prev)) {
for (const key in prev) {
if (!next[key]) {
if (next[key] == null) {
setStyle(style, key, '')
}
}
} else {
for (const prevStyle of prev.split(';')) {
const key = prevStyle.slice(0, prevStyle.indexOf(':')).trim()
if (!next[key]) {
if (next[key] == null) {
setStyle(style, key, '')
}
}
@ -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(