fix(runtime-dom): consistently remove boolean attributes for falsy values (#4348)

This commit is contained in:
skirtle
2021-08-16 23:18:36 +01:00
committed by GitHub
parent f855ccb2c1
commit 620a69b871
12 changed files with 70 additions and 22 deletions

View File

@@ -1,4 +1,9 @@
import { isSpecialBooleanAttr, makeMap, NOOP } from '@vue/shared'
import {
includeBooleanAttr,
isSpecialBooleanAttr,
makeMap,
NOOP
} from '@vue/shared'
import {
compatUtils,
ComponentInternalInstance,
@@ -28,7 +33,7 @@ export function patchAttr(
// note we are only checking boolean attributes that don't have a
// corresponding dom prop of the same name here.
const isBoolean = isSpecialBooleanAttr(key)
if (value == null || (isBoolean && value === false)) {
if (value == null || (isBoolean && !includeBooleanAttr(value))) {
el.removeAttribute(key)
} else {
el.setAttribute(key, isBoolean ? '' : value)

View File

@@ -3,6 +3,7 @@
// This can come from explicit usage of v-html or innerHTML as a prop in render
import { warn, DeprecationTypes, compatUtils } from '@vue/runtime-core'
import { includeBooleanAttr } from '@vue/shared'
// functions. The user is responsible for using them with only trusted content.
export function patchDOMProp(
@@ -41,9 +42,9 @@ export function patchDOMProp(
if (value === '' || value == null) {
const type = typeof el[key]
if (value === '' && type === 'boolean') {
if (type === 'boolean') {
// e.g. <select multiple> compiles to { multiple: '' }
el[key] = true
el[key] = includeBooleanAttr(value)
return
} else if (value == null && type === 'string') {
// e.g. <div :id="null">