Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ describe('render', () => {
expect(render(<div foo={0} />)).to.equal(`<div foo="0"></div>`);
});

it('should include boolean aria-* attributes', () => {
let rendered = render(<div aria-hidden aria-whatever={false} />),
expected = `<div aria-hidden="true" aria-whatever="false"></div>`;

expect(rendered).to.equal(expected);
});

describe('attribute name sanitization', () => {
it('should omit attributes with invalid names', () => {
let rendered = render(h('div', {
Expand Down