Skip to content

Commit

Permalink
fix(runtime-dom): fix width and height prop check condition
Browse files Browse the repository at this point in the history
close #9762
  • Loading branch information
yyx990803 committed Dec 7, 2023
1 parent d74d364 commit 5b00286
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/runtime-dom/__tests__/patchProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ describe('runtime-dom: props patching', () => {
expect(el.getAttribute('width')).toBe('24px')
})

// # 9762 should fallthrough to `key in el` logic for non embedded tags
test('width and height on custom elements', () => {
const el = document.createElement('foobar')
patchProp(el, 'width', null, '24px')
expect(el.getAttribute('width')).toBe('24px')
})

test('translate attribute', () => {
const el = document.createElement('div')
patchProp(el, 'translate', null, 'no')
Expand Down
6 changes: 4 additions & 2 deletions packages/runtime-dom/src/patchProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ function shouldSetAsProp(
// #8780 the width or height of embedded tags must be set as attribute
if (key === 'width' || key === 'height') {
const tag = el.tagName
return !(
if (
tag === 'IMG' ||
tag === 'VIDEO' ||
tag === 'CANVAS' ||
tag === 'SOURCE'
)
) {
return false
}
}

// native onclick with string value, must be set as attribute
Expand Down

0 comments on commit 5b00286

Please sign in to comment.