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..da2264f75 100644 --- a/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts +++ b/accessibility-checker-engine/src/v2/checker/accessibility/util/legacy.ts @@ -2521,13 +2521,14 @@ 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.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 @@ -2642,7 +2643,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/input_label_before.ts b/accessibility-checker-engine/src/v4/rules/input_label_before.ts index 8baf9905e..0c00169d1 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,14 +58,21 @@ 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; } let value = RPTUtil.compareNodeOrder(labelElem, ruleContext); - if (value == -2) { + 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/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/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 @@