From da3e96e41a91632ec5d7729e0c51e0a573e73f2f Mon Sep 17 00:00:00 2001 From: Paulo Pereira Date: Wed, 23 Sep 2020 13:02:29 +0200 Subject: [PATCH] feat: add better support for aria-* attrs --- index.js | 2 +- test/index.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a3e2541..438cb06 100644 --- a/index.js +++ b/index.js @@ -104,7 +104,7 @@ function context () { e.setAttribute(v, l[k][v]) } } - else if (k.substr(0, 5) === "data-") { + else if (/^(data|aria)-/.test(k)) { e.setAttribute(k, l[k]) } else { e[k] = l[k] diff --git a/test/index.js b/test/index.js index c007cc5..ecc0408 100644 --- a/test/index.js +++ b/test/index.js @@ -82,6 +82,12 @@ test('sets data attributes', function(t){ t.end() }) +test('sets aria attributes', function(t){ + var div = h('div', {'aria-label': 'Close'}) + t.equal(div.getAttribute('aria-label'), 'Close') + t.end() +}) + test('boolean, number, date, regex get to-string\'ed', function(t){ var e = h('p', true, false, 4, new Date('Mon Jan 15 2001'), /hello/) t.assert(e.outerHTML.match(/

truefalse4Mon Jan 15.+2001.*\/hello\/<\/p>/))