diff --git a/lib/rules/empty-heading.json b/lib/rules/empty-heading.json index 5f978b5894..df0534e6f9 100644 --- a/lib/rules/empty-heading.json +++ b/lib/rules/empty-heading.json @@ -1,6 +1,7 @@ { "id": "empty-heading", "selector": "h1, h2, h3, h4, h5, h6, [role=\"heading\"]", + "matches": "heading-matches.js", "tags": [ "cat.name-role-value", "best-practice" @@ -11,9 +12,7 @@ }, "all": [], "any": [ - "has-visible-text", - "role-presentation", - "role-none" + "has-visible-text" ], "none": [] } diff --git a/lib/rules/heading-matches.js b/lib/rules/heading-matches.js new file mode 100644 index 0000000000..0edcd1599b --- /dev/null +++ b/lib/rules/heading-matches.js @@ -0,0 +1,13 @@ +// Get all valid roles +let explicitRoles; +if (node.hasAttribute('role')) { + explicitRoles = node.getAttribute('role').split(/\s+/i) + .filter(axe.commons.aria.isValidRole); +} + +// Check valid roles if there are any, otherwise fall back to the inherited role +if (explicitRoles && explicitRoles.length > 0) { + return explicitRoles.includes('heading'); +} else { + return axe.commons.aria.implicitRole(node) === 'heading'; +} diff --git a/lib/rules/heading-order.json b/lib/rules/heading-order.json index f9150bacee..c9372ad242 100644 --- a/lib/rules/heading-order.json +++ b/lib/rules/heading-order.json @@ -1,6 +1,7 @@ { "id": "heading-order", "selector": "h1, h2, h3, h4, h5, h6, [role=heading]", + "matches": "heading-matches.js", "tags": [ "cat.semantics", "best-practice" diff --git a/test/integration/rules/empty-heading/empty-heading.html b/test/integration/rules/empty-heading/empty-heading.html index d37d118d33..8e6c2693c9 100644 --- a/test/integration/rules/empty-heading/empty-heading.html +++ b/test/integration/rules/empty-heading/empty-heading.html @@ -6,6 +6,8 @@
+