Skip to content

Commit 9b8ea9c

Browse files
committed
Stringify boolean aria-* attributes
Signed-off-by: Sven Tschui <[email protected]>
1 parent 09d7675 commit 9b8ea9c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
176176
v = styleObjToCss(v);
177177
}
178178

179+
// always use string values instead of booleans for aria attributes
180+
// also see https://github.com/preactjs/preact/pull/2347/files
181+
if (name[0] === 'a' && name['1'] === 'r' && typeof v === 'boolean') {
182+
v = String(v);
183+
}
184+
179185
let hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent);
180186
if (hooked || hooked==='') {
181187
s += hooked;

test/render.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ describe('render', () => {
5757
expect(render(<div foo={0} />)).to.equal(`<div foo="0"></div>`);
5858
});
5959

60+
it('should include boolean aria-* attributes', () => {
61+
let rendered = render(<div aria-hidden aria-whatever={false} />),
62+
expected = `<div aria-hidden="true" aria-whatever="false"></div>`;
63+
64+
expect(rendered).to.equal(expected);
65+
});
66+
6067
describe('attribute name sanitization', () => {
6168
it('should omit attributes with invalid names', () => {
6269
let rendered = render(h('div', {

0 commit comments

Comments
 (0)