Add rule to prevent duplicate labels on TextInput - #366
Merged
Conversation
🦋 Changeset detectedLatest commit: e73a2bd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new ESLint rule a11y-no-duplicate-form-labels that prevents accessibility issues by disallowing aria-label on TextInput components when a FormControl.Label is already present in the parent FormControl.
Key changes:
- Implementation of the new accessibility rule with proper JSX traversal logic
- Comprehensive test coverage for valid and invalid scenarios
- Integration into the recommended configuration and plugin exports
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/rules/a11y-no-duplicate-form-labels.js | Core rule implementation with JSX element detection and parent traversal logic |
| src/rules/tests/a11y-no-duplicate-form-labels.test.js | Comprehensive test suite covering valid and invalid use cases |
| src/index.js | Exports the new rule in the main plugin module |
| src/configs/recommended.js | Adds the rule to the recommended configuration as an error |
| docs/rules/a11y-no-duplicate-form-labels.md | Documentation with examples of correct and incorrect usage |
| .changeset/gold-pigs-carry.md | Changeset file for release notes |
Comments suppressed due to low confidence (1)
src/rules/tests/a11y-no-duplicate-form-labels.test.js:33
- The test comment indicates that visuallyHidden FormControl.Label should be valid, but line 86-94 shows this scenario should actually trigger an error. The test case and comment are contradictory - either the test case should be moved to invalid section or the rule logic should be updated to handle visuallyHidden differently.
// TextInput with visuallyHidden FormControl.Label is valid
TylerJDev
approved these changes
Jul 14, 2025
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| 'eslint-plugin-primer-react': patch | |||
Member
There was a problem hiding this comment.
I think we could make this minor
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add a new rule
a11y-no-duplicate-form-labelsthat prevents duplicate labels on form inputs by disallowingaria-labelonTextInputwhenFormControl.Labelis present.Fixes: #4393