( el: Element, key: string, value: unknown, isSVG: boolean, )
| 82 | } |
| 83 | |
| 84 | function shouldSetAsProp( |
| 85 | el: Element, |
| 86 | key: string, |
| 87 | value: unknown, |
| 88 | isSVG: boolean, |
| 89 | ) { |
| 90 | if (isSVG) { |
| 91 | // most keys must be set as attribute on svg elements to work |
| 92 | // ...except innerHTML & textContent |
| 93 | if (key === 'innerHTML' || key === 'textContent') { |
| 94 | return true |
| 95 | } |
| 96 | // or native onclick with function values |
| 97 | if (key in el && isNativeOn(key) && isFunction(value)) { |
| 98 | return true |
| 99 | } |
| 100 | return false |
| 101 | } |
| 102 | |
| 103 | // these are enumerated attrs, however their corresponding DOM properties |
| 104 | // are actually booleans - this leads to setting it with a string "false" |
| 105 | // value leading it to be coerced to `true`, so we need to always treat |
| 106 | // them as attributes. |
| 107 | // Note that `contentEditable` doesn't have this problem: its DOM |
| 108 | // property is also enumerated string values. |
| 109 | if ( |
| 110 | key === 'spellcheck' || |
| 111 | key === 'draggable' || |
| 112 | key === 'translate' || |
| 113 | key === 'autocorrect' |
| 114 | ) { |
| 115 | return false |
| 116 | } |
| 117 | |
| 118 | // #13946 iframe.sandbox should always be set as attribute since setting |
| 119 | // the property to null results in 'null' string, and setting to empty string |
| 120 | // enables the most restrictive sandbox mode instead of no sandboxing. |
| 121 | if (key === 'sandbox' && el.tagName === 'IFRAME') { |
| 122 | return false |
| 123 | } |
| 124 | |
| 125 | // #1787, #2840 form property on form elements is readonly and must be set as |
| 126 | // attribute. |
| 127 | if (key === 'form') { |
| 128 | return false |
| 129 | } |
| 130 | |
| 131 | // #1526 <input list> must be set as attribute |
| 132 | if (key === 'list' && el.tagName === 'INPUT') { |
| 133 | return false |
| 134 | } |
| 135 | |
| 136 | // #2766 <textarea type> must be set as attribute |
| 137 | if (key === 'type' && el.tagName === 'TEXTAREA') { |
| 138 | return false |
| 139 | } |
| 140 | |
| 141 | // #8780 the width or height of embedded tags must be set as attribute |
no test coverage detected