Add accessible label/input associations to reusable form fields#69
Open
jaynomyaro wants to merge 1 commit into
Open
Add accessible label/input associations to reusable form fields#69jaynomyaro wants to merge 1 commit into
jaynomyaro wants to merge 1 commit into
Conversation
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.
PR: Add Accessible Label/Input Associations to Reusable Form Fields
Summary
Improve form accessibility by ensuring all reusable form components correctly associate labels with their corresponding inputs.
This PR introduces proper label/input relationships across shared form components, improving usability for screen reader users, keyboard navigation, and overall compliance with accessibility standards.
Problem
Several reusable form fields currently do not consistently associate labels with their inputs:
Some inputs are missing unique id attributes.
Labels are not always linked using htmlFor.
Screen readers may not correctly announce field labels.
Clicking a label does not always focus the associated input.
Accessibility testing tools report form labeling violations.
Solution
Standardize accessible label associations across all reusable form components.
Core Changes
Generate or accept stable, unique id values for form controls.
Associate labels with controls using htmlFor.
Ensure every rendered form field has an accessible name.
Preserve backward compatibility for existing component consumers.
Add support for custom IDs when explicitly provided.
Component Updates
TextField
Input
Textarea
Select
Checkbox
RadioGroup
Any wrapper components rendering form controls
Example
const generatedId = id ?? useId();
{label}
<input id={generatedId} {...props} />
Accessibility Improvements
Screen readers correctly announce field labels.
Clicking labels moves focus to the corresponding control.
Improved keyboard and assistive technology support.
Better compliance with WCAG and accessibility best practices.
Reduced accessibility violations in automated audits.
Testing
Added tests covering:
Labels render with matching htmlFor values.
Inputs receive stable IDs.
Custom IDs override generated IDs.
Label clicks correctly focus associated controls.
Components expose accessible names to assistive technologies.
Accessibility tests pass with React Testing Library and axe checks.
Benefits
Improves accessibility for users relying on assistive technologies.
Creates consistent behavior across all form components.
Simplifies development by standardizing field implementations.
Reduces accessibility regressions in future form development.
Enhances overall user experience and standards compliance.
Breaking Changes
None.
All changes are backward compatible. Existing consumers continue to function while automatically benefiting from improved accessibility. closed #64