diff --git a/src/index.js b/src/index.js index 31fe52fa..a6878716 100644 --- a/src/index.js +++ b/src/index.js @@ -176,6 +176,12 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) { v = styleObjToCss(v); } + // always use string values instead of booleans for aria attributes + // also see https://github.com/preactjs/preact/pull/2347/files + if (name[0] === 'a' && name['1'] === 'r' && typeof v === 'boolean') { + v = String(v); + } + let hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent); if (hooked || hooked==='') { s += hooked; diff --git a/test/render.js b/test/render.js index 3095d66a..d2252648 100644 --- a/test/render.js +++ b/test/render.js @@ -57,6 +57,13 @@ describe('render', () => { expect(render(
)).to.equal(``); }); + it('should include boolean aria-* attributes', () => { + let rendered = render(), + expected = ``; + + expect(rendered).to.equal(expected); + }); + describe('attribute name sanitization', () => { it('should omit attributes with invalid names', () => { let rendered = render(h('div', {