Skip to content

Commit 54d9a02

Browse files
authored
Merge pull request #135 from microsoft/user/aubreyquinn/bugFix
User/aubreyquinn/bug fix
2 parents 65163aa + 607a961 commit 54d9a02

5 files changed

+22
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
const dropdownBasedComponents = ["Dropdown"];
5+
6+
export { dropdownBasedComponents };

lib/rules/dropdown-needs-labelling.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { elementType } from "jsx-ast-utils";
66
import { hasAssociatedLabelViaAriaLabelledBy, hasAssociatedLabelViaHtmlFor, isInsideLabelTag } from "../util/labelUtils";
77
import { hasNonEmptyProp } from "../util/hasNonEmptyProp";
88
import { JSXOpeningElement } from "estree-jsx";
9+
import { dropdownBasedComponents } from "../applicableComponents/dropdownBasedComponents";
910

1011
//------------------------------------------------------------------------------
1112
// Rule Definition
@@ -34,7 +35,7 @@ const rule = ESLintUtils.RuleCreator.withoutDocs({
3435
// visitor functions for different types of nodes
3536
JSXOpeningElement(node: TSESTree.JSXOpeningElement) {
3637
// if it is not a Dropdown, return
37-
if (elementType(node as JSXOpeningElement) !== "Dropdown") {
38+
if (!dropdownBasedComponents.includes(elementType(node as unknown as JSXOpeningElement))) {
3839
return;
3940
}
4041

lib/rules/visual-label-better-than-aria-suggestion.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { hasNonEmptyProp } from "../util/hasNonEmptyProp";
55
import { applicableComponents } from "../applicableComponents/inputBasedComponents";
6+
import { dropdownBasedComponents } from "../applicableComponents/dropdownBasedComponents";
67
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
78
import { elementType } from "jsx-ast-utils";
89
import { JSXOpeningElement } from "estree-jsx";
@@ -34,7 +35,7 @@ const rule = ESLintUtils.RuleCreator.withoutDocs({
3435
// visitor functions for different types of nodes
3536
JSXOpeningElement(node: TSESTree.JSXOpeningElement) {
3637
// if it is not a listed component, return
37-
if (!applicableComponents.includes(elementType(node as unknown as JSXOpeningElement))) {
38+
if (![dropdownBasedComponents, ...applicableComponents].includes(elementType(node as unknown as JSXOpeningElement))) {
3839
return;
3940
}
4041

lib/util/hasLabelledChildImage.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@ const isJSXIdentifierWithName = (name: TSESTree.JSXTagNameExpression, validNames
2525
* @returns boolean
2626
*/
2727
const hasLabelledChildImage = (node: TSESTree.JSXElement): boolean => {
28-
console.log("node::", node);
2928
if (!node.children || node.children.length === 0) {
3029
return false;
3130
}
3231

3332
return flattenChildren(node).some(child => {
3433
if (child.type === "JSXElement" && isJSXIdentifierWithName(child.openingElement.name, mergedImageComponents)) {
3534
const attributes = child.openingElement.attributes;
36-
console.log("attributes::", attributes);
37-
console.log("hasAccessibilityAttributes(attributes)", hasAccessibilityAttributes(attributes));
38-
console.log("!isImageHidden(attributes)", !isImageHidden(attributes));
39-
4035
return !isImageHidden(attributes) && hasAccessibilityAttributes(attributes);
4136
}
4237
return false;
@@ -68,23 +63,32 @@ const isImageHidden = (attributes: TSESTree.JSXOpeningElement["attributes"]): bo
6863
return true;
6964
}
7065

71-
// Check if the image has an `aria-label` attribute with a non-empty value
66+
// Check if the image has an `aria-label` or `aria-labelledby` attribute with a non-empty value
7267
const ariaLabelProp = getProp(attributes as unknown as JSXOpeningElement["attributes"], "aria-label");
68+
const ariaLabelledbyProp = getProp(attributes as unknown as JSXOpeningElement["attributes"], "aria-labelledby");
69+
7370
if (ariaLabelProp) {
7471
const ariaLabelValue = getPropValue(ariaLabelProp);
7572
if (ariaLabelValue) {
7673
return false; // If `aria-label` is present and has a value, the image is not hidden
7774
}
7875
}
7976

77+
if (ariaLabelledbyProp) {
78+
const ariaLabelledbyValue = getPropValue(ariaLabelledbyProp);
79+
if (ariaLabelledbyValue) {
80+
return false; // If `aria-labelledby` is present and has a value, the image is not hidden
81+
}
82+
}
83+
8084
// Check if the image has an `alt` attribute and return true if the `alt` value is falsy
8185
const altProp = getProp(attributes as unknown as JSXOpeningElement["attributes"], "alt");
8286
if (altProp) {
8387
const altValue = getPropValue(altProp);
8488
return !altValue; // Returns true if `altValue` is falsy (e.g., empty string, null, or undefined)
8589
}
8690

87-
return true; // If neither `alt` nor `aria-label` is present, consider the image hidden
91+
return true; // If neither `alt`, `aria-label`, nor `aria-labelledby` is present, consider the image hidden
8892
};
8993

9094
export { hasLabelledChildImage, isImageHidden, hasAccessibilityAttributes, isJSXIdentifierWithName };

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/eslint-plugin-fluentui-jsx-a11y",
3-
"version": "3.0.0-alpha.1",
3+
"version": "3.0.0-alpha.2",
44
"description": "Static AST checker for accessibility rules on FluentUI JSX elements.",
55
"keywords": [
66
"eslint",

0 commit comments

Comments
 (0)