diff --git a/examples/basic/app.js b/examples/basic/app.js index d7aa71a..3780d7d 100644 --- a/examples/basic/app.js +++ b/examples/basic/app.js @@ -20,6 +20,9 @@ new Vue({ headAttrs: { test: true }, + bodyAttrs: { + tabIndex: 0 + }, meta: [ { name: 'description', content: 'Hello', vmid: 'test' } ], diff --git a/src/client/updaters/attribute.js b/src/client/updaters/attribute.js index e0e92cb..ae026ca 100644 --- a/src/client/updaters/attribute.js +++ b/src/client/updaters/attribute.js @@ -28,7 +28,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) { // remove attributes from the map // which have been removed for this appId for (const attr in data) { - if (data[attr] && appId in data[attr]) { + if (data[attr] !== undefined && appId in data[attr]) { toUpdate.push(attr) if (!attrs[attr]) { @@ -43,7 +43,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) { if (!attrData || attrData[appId] !== attrs[attr]) { toUpdate.push(attr) - if (attrs[attr]) { + if (attrs[attr] !== undefined) { data[attr] = data[attr] || {} data[attr][appId] = attrs[attr] } @@ -61,7 +61,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) { if (attrValues.length) { const attrValue = includes(booleanHtmlAttributes, attr) && attrValues.some(Boolean) ? '' - : attrValues.filter(Boolean).join(' ') + : attrValues.filter(v => v !== undefined).join(' ') tag.setAttribute(attr, attrValue) } else { diff --git a/test/utils/meta-info-data.js b/test/utils/meta-info-data.js index d2ef247..7f4b316 100644 --- a/test/utils/meta-info-data.js +++ b/test/utils/meta-info-data.js @@ -270,8 +270,8 @@ const metaInfoData = { }, bodyAttrs: { add: { - data: { foo: 'bar', fizz: ['fuzz', 'fozz'] }, - expect: [''], + data: { foo: 'bar', fizz: ['fuzz', 'fozz'], falsy: 0 }, + expect: [''], test (side, defaultTest) { return () => { if (side === 'client') { @@ -284,7 +284,8 @@ const metaInfoData = { expect(attributeMap).toEqual({ bodyAttrs: { foo: { ssr: 'bar' }, - fizz: { ssr: ['fuzz', 'fozz'] } + fizz: { ssr: ['fuzz', 'fozz'] }, + falsy: { ssr: 0 } } }) } @@ -298,7 +299,7 @@ const metaInfoData = { return () => { defaultTest() - expect(attributeMap).toEqual({ bodyAttrs: { foo: { ssr: 'baz' }, fizz: {} } }) + expect(attributeMap).toEqual({ bodyAttrs: { foo: { ssr: 'baz' }, fizz: {}, falsy: {} } }) } } }, @@ -309,7 +310,7 @@ const metaInfoData = { return () => { defaultTest() - expect(attributeMap).toEqual({ bodyAttrs: { foo: {}, fizz: {} } }) + expect(attributeMap).toEqual({ bodyAttrs: { foo: {}, fizz: {}, falsy: {} } }) } } }