fix(runtime-dom): properly handle style properties with undefined values (#5348)
fix #5322
This commit is contained in:
		
							parent
							
								
									f4d2c9fc6a
								
							
						
					
					
						commit
						85af139863
					
				@ -37,7 +37,18 @@ describe(`runtime-dom: style patching`, () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  it('remove if falsy value', () => {
 | 
					  it('remove if falsy value', () => {
 | 
				
			||||||
    const el = document.createElement('div')
 | 
					    const el = document.createElement('div')
 | 
				
			||||||
    patchProp(el, 'style', { color: 'red' }, { color: undefined })
 | 
					    patchProp(el, 'style', null, {
 | 
				
			||||||
 | 
					      color: undefined,
 | 
				
			||||||
 | 
					      borderRadius: null
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    expect(el.style.cssText.replace(/\s/g, '')).toBe('')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    patchProp(
 | 
				
			||||||
 | 
					      el,
 | 
				
			||||||
 | 
					      'style',
 | 
				
			||||||
 | 
					      { color: 'red' },
 | 
				
			||||||
 | 
					      { color: null, borderRadius: undefined }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    expect(el.style.cssText.replace(/\s/g, '')).toBe('')
 | 
					    expect(el.style.cssText.replace(/\s/g, '')).toBe('')
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -45,6 +45,7 @@ function setStyle(
 | 
				
			|||||||
  if (isArray(val)) {
 | 
					  if (isArray(val)) {
 | 
				
			||||||
    val.forEach(v => setStyle(style, name, v))
 | 
					    val.forEach(v => setStyle(style, name, v))
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
 | 
					    if (val == null) val = ''
 | 
				
			||||||
    if (name.startsWith('--')) {
 | 
					    if (name.startsWith('--')) {
 | 
				
			||||||
      // custom property definition
 | 
					      // custom property definition
 | 
				
			||||||
      style.setProperty(name, val)
 | 
					      style.setProperty(name, val)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user