From 44b4ece16bc43eb22c617dbf98ac0feb75a14009 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Mon, 27 Nov 2023 14:18:49 -0600 Subject: [PATCH 1/4] initial rule update and test cases #1557 --- .../v2/checker/accessibility/util/legacy.ts | 8 +- .../src/v4/rules/label_content_exists.ts | 2 +- .../label-invisible-element.html | 139 ++++++++++++++++++ 3 files changed, 144 insertions(+), 5 deletions(-) create mode 100755 accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html diff --git a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts index ea406635d..616925b0d 100644 --- a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts +++ b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts @@ -2521,9 +2521,9 @@ export class RPTUtil { public static isInnerTextOnlyEmpty(element) { // Get the innerText of the element let text = element.innerText; - - if (text === undefined && element.textContent !== undefined) { - // In headless mode, innerText is sometimes 'undefined' + + if ((text === undefined || !text || text.trim().length === 0) && element.textContent !== undefined) { + // innerText is sometimes 'undefined' in headless mode, or null if the element is invisible or not erxpanded // so we try textContent as a workaround text = element.textContent } @@ -2642,7 +2642,7 @@ export class RPTUtil { node.nodeName.toLowerCase() === "svg" && RPTUtil.svgHasName(node as any) ); - + // Now we check if this node is of type element, visible if (!hasContent && node.nodeType === 1 && VisUtil.isNodeVisible(node)) { // Check if the innerText of the element is empty or not diff --git a/accessibility-checker-engine/src/v4/rules/label_content_exists.ts b/accessibility-checker-engine/src/v4/rules/label_content_exists.ts index eaffd71b9..dc9f734cb 100644 --- a/accessibility-checker-engine/src/v4/rules/label_content_exists.ts +++ b/accessibility-checker-engine/src/v4/rules/label_content_exists.ts @@ -11,7 +11,7 @@ limitations under the License. *****************************************************************************/ -import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule"; +import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule"; import { eRulePolicy, eToolkitLevel } from "../api/IRule"; import { RPTUtil } from "../../v2/checker/accessibility/util/legacy"; import { FragmentUtil } from "../../v2/checker/accessibility/util/fragment"; diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html new file mode 100755 index 000000000..7be0c21ff --- /dev/null +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html @@ -0,0 +1,139 @@ + + + + + + Shadow DOM input Label + + + +
+
+
+ Detail summary +
+ + +
+
+
+ Direct Detail summary +
+ + +
+
+
+ Div summary +
+ + +
+
+
+ Direct Div summary +
+ + +
+
+
+
+ + + From 98df636aca4fe04721ff243f05a2c3ce7f489ab6 Mon Sep 17 00:00:00 2001 From: Shunguo Date: Tue, 28 Nov 2023 11:35:20 -0600 Subject: [PATCH 2/4] update the rule on label text calculation #1557 --- .../src/v2/checker/accessibility/util/legacy.ts | 5 +++-- .../src/v4/rules/input_label_before.ts | 11 +++++++++-- .../rules/input_label_before_ruleunit/D870.html | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts index 616925b0d..da2264f75 100644 --- a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts +++ b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts @@ -2522,12 +2522,13 @@ export class RPTUtil { // Get the innerText of the element let text = element.innerText; - if ((text === undefined || !text || text.trim().length === 0) && element.textContent !== undefined) { + if ((text === undefined || !text || text.trim().length === 0) && element.nodeName.toLowerCase() !== 'slot' && element.textContent !== undefined) { + //ignore slot because its text will be filled by the corresponding content in the light DOM // innerText is sometimes 'undefined' in headless mode, or null if the element is invisible or not erxpanded // so we try textContent as a workaround text = element.textContent } - + let retVal = !(text !== null && text.trim().length > 0); if (element.nodeType === 1 && element.nodeName.toLowerCase() === "slot") { //TODO: need to conside its own content, a slot may have its own content or assigned content diff --git a/accessibility-checker-engine/src/v4/rules/input_label_before.ts b/accessibility-checker-engine/src/v4/rules/input_label_before.ts index 8baf9905e..7e6161642 100644 --- a/accessibility-checker-engine/src/v4/rules/input_label_before.ts +++ b/accessibility-checker-engine/src/v4/rules/input_label_before.ts @@ -11,7 +11,7 @@ limitations under the License. *****************************************************************************/ -import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule"; +import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule"; import { eRulePolicy, eToolkitLevel } from "../api/IRule"; import { RPTUtil } from "../../v2/checker/accessibility/util/legacy"; @@ -58,7 +58,7 @@ export let input_label_before: Rule = { // Get only the non-hidden labels for element let labelElem = RPTUtil.getLabelForElementHidden(ruleContext, true); - + if (labelElem == null || !RPTUtil.hasInnerContentHidden(labelElem)) { // Due to dependency, label must be done via title - this rule doesn't apply return null; @@ -66,6 +66,13 @@ export let input_label_before: Rule = { let value = RPTUtil.compareNodeOrder(labelElem, ruleContext); if (value == -2) { + // ignore if no label or the content for the label is only from the nested input control + let text = RPTUtil.getInnerText(ruleContext); + if (text && text.trim().length > 0 && RPTUtil.getInnerText(ruleContext).trim() === text.trim()) { + // Due to dependency, label must be done via title - this rule doesn't apply + return null; + } + // input nested in label let passed = false; let walkNode = ruleContext.previousSibling; diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/input_label_before_ruleunit/D870.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/input_label_before_ruleunit/D870.html index eaf204ad8..e556282dd 100755 --- a/accessibility-checker-engine/test/v2/checker/accessibility/rules/input_label_before_ruleunit/D870.html +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/input_label_before_ruleunit/D870.html @@ -46,7 +46,7 @@

Input type Tests

From 7e6d78c1ff3621c503f131c91beeed27a672190b Mon Sep 17 00:00:00 2001 From: Shunguo Date: Tue, 28 Nov 2023 12:02:45 -0600 Subject: [PATCH 3/4] Update label-invisible-element.html --- .../label-invisible-element.html | 52 +------------------ 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html index 7be0c21ff..2820d9223 100755 --- a/accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/label_content_exists_ruleunit/label-invisible-element.html @@ -34,7 +34,7 @@ -
+