From 92b69462f2b7499f3679a0d5ee7f2803521050c6 Mon Sep 17 00:00:00 2001 From: hsiao Date: Mon, 21 Oct 2024 11:56:57 +0800 Subject: [PATCH 1/2] Update labelUtils.js --- lib/util/labelUtils.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/util/labelUtils.js b/lib/util/labelUtils.js index f3179b6..459e48d 100644 --- a/lib/util/labelUtils.js +++ b/lib/util/labelUtils.js @@ -142,6 +142,17 @@ function hasAssociatedAriaText(openingElement, context, ariaAttribute) { return hasAssociatedAriaText && hasHtmlId; } +/** + * Determines if the element has a non-empty aria-label attribute. + * e.g. + * + * @param {*} openingElement + * @returns boolean for match found or not. + */ +function hasAriaLabel(openingElement) { + return hasNonEmptyProp(openingElement.attributes, "aria-label"); +} + module.exports = { isInsideLabelTag, hasLabelWithHtmlForId, @@ -149,5 +160,6 @@ module.exports = { hasAssociatedLabelViaAriaLabelledBy, hasAssociatedLabelViaHtmlFor, hasAssociatedLabelViaAriaDescribedby, - hasAssociatedAriaText + hasAssociatedAriaText, + hasAriaLabel }; From acebaf505822e372a89530c28492287774b3a41b Mon Sep 17 00:00:00 2001 From: hsiao Date: Mon, 21 Oct 2024 11:59:20 +0800 Subject: [PATCH 2/2] Update input-components-require-accessible-name.ts --- lib/rules/input-components-require-accessible-name.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rules/input-components-require-accessible-name.ts b/lib/rules/input-components-require-accessible-name.ts index 9fa0c88..763346b 100644 --- a/lib/rules/input-components-require-accessible-name.ts +++ b/lib/rules/input-components-require-accessible-name.ts @@ -3,7 +3,7 @@ import { ESLintUtils, TSESTree } from "@typescript-eslint/utils"; import { elementType } from "jsx-ast-utils"; -import { isInsideLabelTag, hasAssociatedLabelViaHtmlFor, hasAssociatedLabelViaAriaLabelledBy } from "../util/labelUtils"; +import { isInsideLabelTag, hasAssociatedLabelViaHtmlFor, hasAssociatedLabelViaAriaLabelledBy, hasAriaLabel } from "../util/labelUtils"; import { hasFieldParent } from "../util/hasFieldParent"; import { applicableComponents } from "../applicableComponents/inputBasedComponents"; import { JSXOpeningElement } from "estree-jsx"; @@ -41,8 +41,9 @@ const rule = ESLintUtils.RuleCreator.withoutDocs({ return; } - // wrapped in Label tag, labelled with htmlFor, labelled with aria-labelledby + // wrapped in Label tag, labelled with htmlFor, labelled with aria-labelledby, labelled with aria-label if ( + hasAriaLabel(node) || hasFieldParent(context) || isInsideLabelTag(context) || hasAssociatedLabelViaHtmlFor(node, context) ||