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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]}"`
|
||||
}, '')
|
||||
|
||||
Reference in New Issue
Block a user