From 5aba4d3794965579092fa33c597b18305eff2835 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Thu, 30 Nov 2023 10:29:49 -0600 Subject: [PATCH 1/3] initial test cases to show false positive #916 --- .../form_control_accesskey.html | 77 +++++++++++++++++++ .../legend_accesskey.html | 44 +++++++++++ 2 files changed, 121 insertions(+) create mode 100755 accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html create mode 100755 accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html new file mode 100755 index 000000000..1a8e8d181 --- /dev/null +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html @@ -0,0 +1,77 @@ + + + + + +word spacing + + +

+ If you need to relax, press the Stress reliever! +

+ + + + HTML
+ CSS + + + + + diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html new file mode 100755 index 000000000..c674d7105 --- /dev/null +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html @@ -0,0 +1,44 @@ + + + + + +word spacing + + +
+ + + + + + +
+ + + + From c4bfdeae4ddd2d7b925024e5f934f824de62877e Mon Sep 17 00:00:00 2001 From: Shunguo Date: Mon, 4 Dec 2023 13:53:08 -0600 Subject: [PATCH 2/3] update the element_accesskey_label rule and add new test cases #916 --- .../v4/rules/element_accesskey_labelled.ts | 57 ++++++++++++------- .../AssesskeyNeedsLabelHidden.html | 2 +- .../form_control_accesskey.html | 57 +------------------ .../legend_accesskey.html | 17 +----- 4 files changed, 40 insertions(+), 93 deletions(-) diff --git a/accessibility-checker-engine/src/v4/rules/element_accesskey_labelled.ts b/accessibility-checker-engine/src/v4/rules/element_accesskey_labelled.ts index 0481b054d..353d1a359 100644 --- a/accessibility-checker-engine/src/v4/rules/element_accesskey_labelled.ts +++ b/accessibility-checker-engine/src/v4/rules/element_accesskey_labelled.ts @@ -11,10 +11,12 @@ limitations under the License. *****************************************************************************/ -import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule"; +import { Rule, RuleResult, RuleContext, RulePotential, RulePass, RuleContextHierarchy } from "../api/IRule"; import { eRulePolicy, eToolkitLevel } from "../api/IRule"; import { RPTUtil } from "../../v2/checker/accessibility/util/legacy"; -import { DOMWalker } from "../../v2/dom/DOMWalker"; +import { VisUtil } from "../../v2/dom/VisUtil"; +import { ARIADefinitions } from "../../v2/aria/ARIADefinitions"; +import { ARIAMapper } from "../../v2/aria/ARIAMapper"; export let element_accesskey_labelled: Rule = { id: "element_accesskey_labelled", @@ -34,8 +36,8 @@ export let element_accesskey_labelled: Rule = { messages: { "en-US": { "Pass_0": "Rule Passed", - "Potential_1": "The HTML element with an assigned 'accesskey' attribute does not have an associated label", - "group": "An HTML element with an assigned 'accesskey' attribute must have an associated label" + "Potential_1": "The element with an assigned 'accesskey' attribute does not have an associated label", + "group": "An element with an assigned 'accesskey' attribute must have an associated label" } }, rulesets: [{ @@ -46,25 +48,36 @@ export let element_accesskey_labelled: Rule = { }], act: [], run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => { - const ruleContext = context["dom"].node as Element; - let passed = false; - if (RPTUtil.attributeNonEmpty(ruleContext, "title")) { - passed = true; - } else if (RPTUtil.attributeNonEmpty(ruleContext, "aria-label")) { - passed = true; - } else if (RPTUtil.getLabelForElementHidden(ruleContext, true)) { // ignore hidden - passed = true; - } else if (RPTUtil.attributeNonEmpty(ruleContext, "aria-labelledby")) { - // assume the validity of the id (of aria-labelledby) is checked by a different rule - passed = true; - } else if (ruleContext.nodeName.toLowerCase() === "input" - && DOMWalker.parentNode(ruleContext).nodeName.toLowerCase() === "label") { - // assume the validity of the label, e.g. empty label, is checked by a different rule - passed = true; - } + const ruleContext = context["dom"].node as HTMLElement; + //skip the check if the element is hidden or disabled + if (!VisUtil.isNodeVisible(ruleContext) || RPTUtil.isNodeDisabled(ruleContext)) + return; + + //skip if the element is tabbable, it's covered by other rules + if (RPTUtil.isTabbable(ruleContext)) + return; + + let roles = RPTUtil.getRoles(ruleContext, true); + //skip the native element, mostly text elements + if (!roles || roles.length === 0) return; + + let patterns = ARIADefinitions.designPatterns[roles[0]] + if (!patterns.nameFrom) + return; + + // ignore if accessble name is required (checked in other rules) or prohibited (text element) + if (patterns.nameRequired || !patterns.nameFrom || patterns.nameFrom.includes("prohibited")) + return; + + //special case: legend, as a child of a fieldset, delegate the accesskey command to the field of the fieldset which is covered by other rules + if (ruleContext.parentElement && ruleContext.parentElement.nodeName.toLowerCase() === 'fieldset') + return; + + // check if accessible name exists + if (ARIAMapper.computeName(ruleContext).trim().length > 0) + return RulePass("Pass_0"); - if (passed) return RulePass("Pass_0"); - if (!passed) return RulePotential("Potential_1"); + return RulePotential("Potential_1"); } } \ No newline at end of file diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/AssesskeyNeedsLabelHidden.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/AssesskeyNeedsLabelHidden.html index bff58d66c..eaa691026 100644 --- a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/AssesskeyNeedsLabelHidden.html +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/AssesskeyNeedsLabelHidden.html @@ -41,7 +41,7 @@ passedXpaths: [ ], failedXpaths: [ - "/html/body/p" + ] } ]; diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html index 1a8e8d181..e430776e4 100755 --- a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/form_control_accesskey.html @@ -4,13 +4,9 @@ -word spacing +accessble key - -

- If you need to relax, press the Stress reliever! -

+ @@ -22,54 +18,7 @@ UnitTest = { ruleIds: ["element_accesskey_labelled"], results: [ - { - "ruleId": "element_accesskey_labelled", - "value": [ - "INFORMATION", - "POTENTIAL" - ], - "path": { - "dom": "/html[1]/body[1]/button[1]", - "aria": "/document[1]/main[1]/button[1]" - }, - "reasonId": "Potential_1", - "message": "The HTML element with an assigned 'accesskey' attribute does not have an associated label", - "messageArgs": [], - "apiArgs": [], - "category": "Accessibility" - }, - { - "ruleId": "element_accesskey_labelled", - "value": [ - "INFORMATION", - "POTENTIAL" - ], - "path": { - "dom": "/html[1]/body[1]/a[1]", - "aria": "/document[1]/main[1]/link[1]" - }, - "reasonId": "Potential_1", - "message": "The HTML element with an assigned 'accesskey' attribute does not have an associated label", - "messageArgs": [], - "apiArgs": [], - "category": "Accessibility" - }, - { - "ruleId": "element_accesskey_labelled", - "value": [ - "INFORMATION", - "POTENTIAL" - ], - "path": { - "dom": "/html[1]/body[1]/a[2]", - "aria": "/document[1]/main[1]/link[2]" - }, - "reasonId": "Potential_1", - "message": "The HTML element with an assigned 'accesskey' attribute does not have an associated label", - "messageArgs": [], - "apiArgs": [], - "category": "Accessibility" - } + ] } diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html index c674d7105..fc3d5e837 100755 --- a/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/element_accesskey_labelled_ruleunit/legend_accesskey.html @@ -21,22 +21,7 @@ UnitTest = { ruleIds: ["element_accesskey_labelled"], results: [ - { - "ruleId": "element_accesskey_labelled", - "value": [ - "INFORMATION", - "POTENTIAL" - ], - "path": { - "dom": "/html[1]/body[1]/fieldset[1]/legend[1]", - "aria": "/document[1]/main[1]/group[1]" - }, - "reasonId": "Potential_1", - "message": "The HTML element with an assigned 'accesskey' attribute does not have an associated label", - "messageArgs": [], - "apiArgs": [], - "category": "Accessibility" - } + ] } From 5ff4fafba4628ae29472a94eb543ee5cfafc2c77 Mon Sep 17 00:00:00 2001 From: Phill Jenkins Date: Thu, 7 Dec 2023 10:04:07 -0600 Subject: [PATCH 3/3] Improve help Changes per box note and Showcase review --- .../en-US/element_accesskey_labelled.html | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/accessibility-checker-engine/help-v4/en-US/element_accesskey_labelled.html b/accessibility-checker-engine/help-v4/en-US/element_accesskey_labelled.html index 21f308a0c..89b42fd7b 100644 --- a/accessibility-checker-engine/help-v4/en-US/element_accesskey_labelled.html +++ b/accessibility-checker-engine/help-v4/en-US/element_accesskey_labelled.html @@ -45,17 +45,19 @@

### Why is this important? -The label of an HTML element with an `accesskey` attribute allows the user agent to display a list of access keys with a name describing each access key’s function. It also allows voice control users to speak the label to activate its function. +The label of an element with an `accesskey` attribute allows the user agent to display a list of access keys with a name describing each access key’s function. +The label also allows voice control users to speak the label to activate its function.
### What to do - * Provide a label using a `title` attribute (e.g. `Activities`); - * **Or**, use `