From 73d52736832637598c416b2e7f2576bc021daa12 Mon Sep 17 00:00:00 2001 From: Jey Date: Thu, 6 Jun 2019 07:26:06 -0400 Subject: [PATCH] feat(rule): New aria-input-field-label rule (#1610) * feat: initial implementation * feat: rule aria-foorm-field-label with new check for no-implicit-explicit-label * update rule * test: fix lint errors * add tests and updates based on review * initial implementation * remove has-visible-text check * update tests --- doc/rule-descriptions.md | 1 + lib/checks/aria/no-implicit-explicit-label.js | 21 ++++ .../aria/no-implicit-explicit-label.json | 11 ++ lib/rules/aria-form-field-label-matches.js | 39 +++++++ lib/rules/aria-input-field-label.json | 13 +++ .../checks/aria/no-implicit-explicit-label.js | 45 ++++++++ .../aria-input-field-label.html | 107 ++++++++++++++++++ .../aria-input-field-label.json | 25 ++++ .../aria-form-field-label-matches.js | 68 +++++++++++ 9 files changed, 330 insertions(+) create mode 100644 lib/checks/aria/no-implicit-explicit-label.js create mode 100644 lib/checks/aria/no-implicit-explicit-label.json create mode 100644 lib/rules/aria-form-field-label-matches.js create mode 100644 lib/rules/aria-input-field-label.json create mode 100644 test/checks/aria/no-implicit-explicit-label.js create mode 100644 test/integration/rules/aria-input-field-label/aria-input-field-label.html create mode 100644 test/integration/rules/aria-input-field-label/aria-input-field-label.json create mode 100644 test/rule-matches/aria-form-field-label-matches.js diff --git a/doc/rule-descriptions.md b/doc/rule-descriptions.md index cfb4e41fd8..4c706af486 100644 --- a/doc/rule-descriptions.md +++ b/doc/rule-descriptions.md @@ -7,6 +7,7 @@ | aria-dpub-role-fallback | Ensures unsupported DPUB roles are only used on elements with implicit fallback roles | Moderate | cat.aria, wcag2a, wcag131 | true | | aria-hidden-body | Ensures aria-hidden='true' is not present on the document body. | Critical | cat.aria, wcag2a, wcag412 | true | | aria-hidden-focus | Ensures aria-hidden elements do not contain focusable elements | Serious | cat.name-role-value, wcag2a, wcag412, wcag131 | true | +| aria-input-field-label | Ensures every ARIA input field has an accessible name | Moderate, Serious | wcag2a, wcag412 | true | | aria-required-attr | Ensures elements with ARIA roles have all required ARIA attributes | Critical | cat.aria, wcag2a, wcag412 | true | | aria-required-children | Ensures elements with an ARIA role that require child roles contain them | Critical | cat.aria, wcag2a, wcag131 | true | | aria-required-parent | Ensures elements with an ARIA role that require parent roles are contained by them | Critical | cat.aria, wcag2a, wcag131 | true | diff --git a/lib/checks/aria/no-implicit-explicit-label.js b/lib/checks/aria/no-implicit-explicit-label.js new file mode 100644 index 0000000000..9c850d8689 --- /dev/null +++ b/lib/checks/aria/no-implicit-explicit-label.js @@ -0,0 +1,21 @@ +const { aria, text } = axe.commons; + +const role = aria.getRole(node, { noImplicit: true }); +this.data(role); + +const labelText = text.sanitize(text.labelText(virtualNode)).toLowerCase(); +const accText = text.sanitize(text.accessibleText(node)).toLowerCase(); + +if (!accText && !labelText) { + return false; +} + +if (!accText && labelText) { + return undefined; +} + +if (!accText.includes(labelText)) { + return undefined; +} + +return false; diff --git a/lib/checks/aria/no-implicit-explicit-label.json b/lib/checks/aria/no-implicit-explicit-label.json new file mode 100644 index 0000000000..4a5a9fc518 --- /dev/null +++ b/lib/checks/aria/no-implicit-explicit-label.json @@ -0,0 +1,11 @@ +{ + "id": "no-implicit-explicit-label", + "evaluate": "no-implicit-explicit-label.js", + "metadata": { + "impact": "moderate", + "messages": { + "pass": "There is no mismatch between a