-
Notifications
You must be signed in to change notification settings - Fork 21
Add accessibility rules for InfoLabel, MenuButton, SplitButton, and Card components #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aubreyquinn
merged 12 commits into
main
from
users/sidhshar/accessibility-rules-for-infolabel-menubutton-splitbutton-and-card-components
Sep 19, 2025
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
028b86d
Add accessibility rules for InfoLabel, MenuButton, SplitButton, and Cβ¦
sidhsharma1992 f491551
Add rule doc.
sidhsharma1992 4c12181
Add rule docs.
sidhsharma1992 95bc83a
Add Readme.
sidhsharma1992 c818570
Remove unused files
sidhsharma1992 1571509
Fix lint issues.
sidhsharma1992 ab0c28e
Comment some tests for hasLabeledChild PR to merge.
sidhsharma1992 a8409bd
Remove Split-button functionality
sidhsharma1992 e87634b
Update Readme
sidhsharma1992 bf01891
Merge branch 'main' of https://github.com/microsoft/eslint-plugin-fluβ¦
sidhsharma1992 740e75b
Update Readme
sidhsharma1992 0e69e5d
Uncomment test cases after the recent merge.
sidhsharma1992 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| # Accessibility: Interactive Card must have an accessible name via aria-label, aria-labelledby, etc (`@microsoft/fluentui-jsx-a11y/card-needs-accessible-name`) | ||
|
|
||
| πΌ This rule is enabled in the β `recommended` config. | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| Interactive Card components must have an accessible name for screen readers. | ||
|
|
||
| ## Rule Details | ||
|
|
||
| This rule enforces that Card components have proper accessible names when they are interactive (clickable). | ||
|
|
||
| ### Noncompliant | ||
|
|
||
| ```jsx | ||
| <Card> | ||
| <CardHeader> | ||
| <Text weight="semibold">Card title</Text> | ||
| </CardHeader> | ||
| </Card> | ||
| ``` | ||
|
|
||
| ### Compliant | ||
|
|
||
| ```jsx | ||
| <Card aria-label="Product details"> | ||
| <CardHeader> | ||
| <Text weight="semibold">Card title</Text> | ||
| </CardHeader> | ||
| </Card> | ||
|
|
||
| <Card aria-labelledby="card-title"> | ||
| <CardHeader> | ||
| <Text id="card-title" weight="semibold">Card title</Text> | ||
| </CardHeader> | ||
| </Card> | ||
| ``` | ||
|
|
||
| ## When Not To Use | ||
|
|
||
| If the Card is purely decorative and not interactive, this rule is not necessary. | ||
|
|
||
| ## Accessibility guidelines | ||
|
|
||
| - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value.html) |
This file contains hidden or 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,37 @@ | ||
| # Accessibility: InfoLabel must have an accessible name via aria-label, text content, aria-labelledby, etc (`@microsoft/fluentui-jsx-a11y/infolabel-needs-labelling`) | ||
|
|
||
| πΌ This rule is enabled in the β `recommended` config. | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| InfoLabel components must have accessible labelling for screen readers. | ||
|
|
||
| ## Rule Details | ||
|
|
||
| This rule enforces that InfoLabel components have proper accessible names through aria-label, aria-labelledby, or text content. | ||
|
|
||
| ### Noncompliant | ||
|
|
||
| ```jsx | ||
| <InfoLabel /> | ||
| ``` | ||
|
|
||
| ### Compliant | ||
|
|
||
| ```jsx | ||
| <InfoLabel aria-label="Additional information" /> | ||
|
|
||
| <InfoLabel aria-labelledby="info-text"> | ||
| <span id="info-text">Help text</span> | ||
| </InfoLabel> | ||
|
|
||
| <InfoLabel>Help information</InfoLabel> | ||
| ``` | ||
|
|
||
| ## When Not To Use | ||
|
|
||
| If the InfoLabel is purely decorative, this rule may not be necessary. | ||
|
|
||
| ## Accessibility guidelines | ||
|
|
||
| - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value.html) |
This file contains hidden or 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,37 @@ | ||
| # Accessibility: MenuButton must have an accessible name via aria-label, text content, aria-labelledby, etc (`@microsoft/fluentui-jsx-a11y/menu-button-needs-labelling`) | ||
|
|
||
| πΌ This rule is enabled in the β `recommended` config. | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| MenuButton components must have accessible labelling for screen readers. | ||
|
|
||
| ## Rule Details | ||
|
|
||
| This rule enforces that MenuButton components have proper accessible names through aria-label, aria-labelledby, or text content. | ||
|
|
||
| ### Noncompliant | ||
|
|
||
| ```jsx | ||
| <MenuButton /> | ||
| ``` | ||
|
|
||
| ### Compliant | ||
|
|
||
| ```jsx | ||
| <MenuButton aria-label="Menu options" /> | ||
|
|
||
| <MenuButton aria-labelledby="menu-label"> | ||
| <span id="menu-label">Options</span> | ||
| </MenuButton> | ||
|
|
||
| <MenuButton>Options</MenuButton> | ||
| ``` | ||
|
|
||
| ## When Not To Use | ||
|
|
||
| This rule should always be used for MenuButton components as they are interactive elements. | ||
|
|
||
| ## Accessibility guidelines | ||
|
|
||
| - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value.html) |
This file contains hidden or 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,37 @@ | ||
| # Accessibility: SplitButton must have an accessible name via aria-label, text content, aria-labelledby, etc (`@microsoft/fluentui-jsx-a11y/split-button-needs-labelling`) | ||
|
|
||
| πΌ This rule is enabled in the β `recommended` config. | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| SplitButton components must have accessible labelling for screen readers. | ||
|
|
||
| ## Rule Details | ||
|
|
||
| This rule enforces that SplitButton components have proper accessible names through aria-label, aria-labelledby, or text content. | ||
|
|
||
| ### Noncompliant | ||
|
|
||
| ```jsx | ||
| <SplitButton /> | ||
| ``` | ||
|
|
||
| ### Compliant | ||
|
|
||
| ```jsx | ||
| <SplitButton aria-label="Save options" /> | ||
|
|
||
| <SplitButton aria-labelledby="save-label"> | ||
| <span id="save-label">Save</span> | ||
| </SplitButton> | ||
|
|
||
| <SplitButton>Save</SplitButton> | ||
| ``` | ||
|
|
||
| ## When Not To Use | ||
|
|
||
| This rule should always be used for SplitButton components as they are interactive elements. | ||
|
|
||
| ## Accessibility guidelines | ||
|
|
||
| - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value.html) |
This file contains hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { ESLintUtils } from "@typescript-eslint/utils"; | ||
| import { makeLabeledControlRule } from "../../util/ruleFactory"; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Rule Definition | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| export default ESLintUtils.RuleCreator.withoutDocs( | ||
| makeLabeledControlRule({ | ||
| component: "MenuButton", | ||
| messageId: "menuButtonNeedsLabelling", | ||
| description: "Accessibility: MenuButton must have an accessible name via aria-label, text content, aria-labelledby, etc.", | ||
| labelProps: ["aria-label"], | ||
| allowFieldParent: false, | ||
| allowHtmlFor: false, | ||
| allowLabelledBy: true, | ||
| allowWrappingLabel: true, | ||
| allowTooltipParent: true, | ||
| allowDescribedBy: false, | ||
| allowLabeledChild: true, | ||
| allowTextContentChild: true | ||
| }) | ||
| ); |
This file contains hidden or 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,26 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { ESLintUtils } from "@typescript-eslint/utils"; | ||
| import { makeLabeledControlRule } from "../../util/ruleFactory"; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Rule Definition | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| export default ESLintUtils.RuleCreator.withoutDocs( | ||
| makeLabeledControlRule({ | ||
| component: "SplitButton", | ||
| messageId: "splitButtonNeedsLabelling", | ||
| description: "Accessibility: SplitButton must have an accessible name via aria-label, text content, aria-labelledby, etc.", | ||
| labelProps: ["aria-label"], | ||
| allowFieldParent: false, | ||
| allowHtmlFor: false, | ||
| allowLabelledBy: true, | ||
| allowWrappingLabel: true, | ||
| allowTooltipParent: true, | ||
| allowDescribedBy: false, | ||
| allowLabeledChild: true, | ||
| allowTextContentChild: true | ||
| }) | ||
| ); | ||
This file contains hidden or 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,26 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { ESLintUtils } from "@typescript-eslint/utils"; | ||
| import { makeLabeledControlRule } from "../util/ruleFactory"; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Rule Definition | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| export default ESLintUtils.RuleCreator.withoutDocs( | ||
| makeLabeledControlRule({ | ||
| component: "Card", | ||
| messageId: "cardNeedsAccessibleName", | ||
| description: "Accessibility: Interactive Card must have an accessible name via aria-label, aria-labelledby, etc.", | ||
| labelProps: ["aria-label"], | ||
| allowFieldParent: false, | ||
| allowHtmlFor: false, | ||
| allowLabelledBy: true, | ||
| allowWrappingLabel: false, | ||
| allowTooltipParent: true, | ||
| allowDescribedBy: false, | ||
| allowLabeledChild: true, | ||
| allowTextContentChild: true | ||
| }) | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.