2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-18 10:51:05 +03:00

fix: only show boolean attrs with truthy value

This commit is contained in:
pimlie
2019-07-11 20:56:34 +02:00
parent 39d9eb6ead
commit 1d9072a3af
5 changed files with 49 additions and 6 deletions
+7 -1
View File
@@ -52,7 +52,13 @@ export default function updateTag(appId, { attribute, tagIDKeyName } = {}, type,
const _attr = includes(dataAttributes, attr)
? `data-${attr}`
: attr
const value = isUndefined(tag[attr]) || includes(booleanHtmlAttributes, attr) ? '' : tag[attr]
const isBooleanAttribute = includes(booleanHtmlAttributes, attr)
if (isBooleanAttribute && !tag[attr]) {
continue
}
const value = isBooleanAttribute ? '' : tag[attr]
newElement.setAttribute(_attr, value)
}
}
+6 -1
View File
@@ -36,7 +36,12 @@ export default function tagGenerator(appId, { attribute, tagIDKeyName } = {}, ty
prefix = 'data-'
}
return isUndefined(tag[attr]) || booleanHtmlAttributes.includes(attr)
const isBooleanAttr = booleanHtmlAttributes.includes(attr)
if (isBooleanAttr && !tag[attr]) {
return attrsStr
}
return isBooleanAttr
? `${attrsStr} ${prefix}${attr}`
: `${attrsStr} ${prefix}${attr}="${tag[attr]}"`
}, '')