Repository navigation
Fix aria-labelledby on Input and DatePicker pointing at a missing label - #429
Open
eastagiletracker wants to merge 1 commit into
Open
eastagiletracker wants to merge 1 commit into
eastagiletracker wants to merge 1 commit into
Conversation
Input and DatePicker (both variants) set aria-labelledby to <id>-label but never rendered an element with that id, so axe reports aria-valid-attr-value on them. Give the label the same id Select and Textarea already use, and only emit aria-labelledby on all five fields when a label is actually rendered.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
This PR proposes fixing
aria-labelledbyonInputandDatePicker, which points at a label id that is never rendered. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/1153. You can sign in with your GitHub ID to claim ownership of the project.What was wrong
getFormItemIdsreturnslabelId(<id>-label), and every form field puts it on its control asaria-labelledby.SelectandTextareaalso render it on their<StyledLabel id={labelId}>, butInput(both the default andtype="color"branches),DatePickerand thedayFormatDayDatePickerrender<StyledLabel htmlFor={id}>without the id. So the reference dangles. Browsers fall back to the<label for>, so the visible label still names the field, but axe reportsaria-valid-attr-value("ARIA attributes must conform to valid values") on these fields. That shows up in the Accessibility panel of your Storybook for everyInputandDatePickerstory, and in any automated audit a consuming app runs. The same dangling reference appears on all five fields when they are rendered without alabel, becausearia-labelledbyis emitted unconditionally.The change
Input,DatePicker,DayDatePicker: the label getsid={labelId}, the same asSelect/Textarea.aria-labelledby={label ? labelId : undefined}, so it is only set when there is a label to point at.No props, exports or styling change. 10 lines across 5 files.
Reproduction and verification
At
main(5b03c75), runnpm run build, then server-render each component fromlib/build.jsinsideCommerce7AdminUIand run axe-core 4.11.4 (the version your a11y addon pulls in) over the markup. Each case renders a field withid: 'f':With this branch, all 10 cases pass: labelled fields reference an existing label, and unlabelled fields carry no
aria-labelledby. A one-minute check in Storybook is to open anyInputorDatePickerstory's Accessibility tab, which flags the violation onmainand is clear on this branch. The repo has no unit-test harness, so I did not add one.tsc --noEmitandeslint srcare clean before and after, andnpm run buildgives the same three webpack bundle-size warnings both times. I left the version bump and release notes to you.How this was managed
This change was tracked as https://eastagiletracker.com/projects/1153/stories/1350695 on a board imported from this repo's pull requests (428 stories), https://eastagiletracker.com/projects/1153, and managed there.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com