-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from microsoft/user/aubreyquinn/tsConverstion
User/aubreyquinn/ts converstion
- Loading branch information
Showing
34 changed files
with
1,304 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const labelBasedComponents = ["Label", "label"]; | ||
const elementsUsedAsLabels = ["div", "span", "p", "h1", "h2", "h3", "h4", "h5", "h6"]; | ||
|
||
export { labelBasedComponents, elementsUsedAsLabels }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils"; | ||
import { hasTextContentChild } from "../util/hasTextContentChild"; | ||
import { hasNonEmptyProp } from "../util/hasNonEmptyProp"; | ||
import { hasAssociatedLabelViaAriaLabelledBy } from "../util/labelUtils"; | ||
import { elementType } from "jsx-ast-utils"; | ||
import { JSXOpeningElement } from "estree-jsx"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
const rule = ESLintUtils.RuleCreator.withoutDocs({ | ||
defaultOptions: [], | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
description: | ||
"This rule aims to ensure that Tabs with icons but no text labels have an accessible name and that Tablist is properly labeled.", | ||
recommended: "strict", | ||
url: "https://www.w3.org/WAI/ARIA/apg/patterns/tabs/" // URL to the documentation page for this rule | ||
}, | ||
fixable: undefined, | ||
schema: [], | ||
messages: { | ||
missingTabLabel: "Accessibility: Tab elements must have an aria-label attribute is there is no visiable text content", | ||
missingTablistLabel: "Accessibility: Tablist must have an accessible label" | ||
} | ||
}, | ||
|
||
create(context) { | ||
return { | ||
// visitor functions for different types of nodes | ||
JSXOpeningElement(node: TSESTree.JSXOpeningElement) { | ||
const elementTypeValue = elementType(node as unknown as JSXOpeningElement); | ||
|
||
// if it is not a Tablist or Tab, return | ||
if (elementTypeValue !== "Tablist" && elementTypeValue !== "Tab") { | ||
return; | ||
} | ||
|
||
// Check for Tablist elements | ||
if (elementTypeValue === "Tablist") { | ||
if ( | ||
// if the Tablist has a label, if the Tablist has an associated label, return | ||
hasNonEmptyProp(node.attributes, "aria-label") || //aria-label | ||
hasAssociatedLabelViaAriaLabelledBy(node, context) // aria-labelledby | ||
) { | ||
return; | ||
} | ||
context.report({ | ||
node, | ||
messageId: "missingTablistLabel" | ||
}); | ||
} | ||
|
||
// Check for Tab elements | ||
if (elementTypeValue === "Tab") { | ||
if ( | ||
hasTextContentChild(node.parent as unknown as TSESTree.JSXElement) || // text content | ||
hasNonEmptyProp(node.attributes, "aria-label") // aria-label | ||
) { | ||
return; | ||
} | ||
context.report({ | ||
node, | ||
messageId: "missingTabLabel" | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
|
||
export default rule; |
Oops, something went wrong.