Skip to content

Fix aria-labelledby on Input and DatePicker pointing at a missing label - #429

Open
eastagiletracker wants to merge 1 commit into
Commerce7:mainfrom
eastagiletracker:agile-board/form-field-aria-labelledby
Open

eastagiletracker wants to merge 1 commit into
Commerce7:mainfrom
eastagiletracker:agile-board/form-field-aria-labelledby

Conversation

@eastagiletracker

Copy link
Copy Markdown

This PR proposes fixing aria-labelledby on Input and DatePicker, 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

getFormItemIds returns labelId (<id>-label), and every form field puts it on its control as aria-labelledby. Select and Textarea also render it on their <StyledLabel id={labelId}>, but Input (both the default and type="color" branches), DatePicker and the dayFormat DayDatePicker render <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 reports aria-valid-attr-value ("ARIA attributes must conform to valid values") on these fields. That shows up in the Accessibility panel of your Storybook for every Input and DatePicker story, and in any automated audit a consuming app runs. The same dangling reference appears on all five fields when they are rendered without a label, because aria-labelledby is emitted unconditionally.

The change

  • Input, DatePicker, DayDatePicker: the label gets id={labelId}, the same as Select/Textarea.
  • All five fields: 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), run npm run build, then server-render each component from lib/build.js inside Commerce7AdminUI and run axe-core 4.11.4 (the version your a11y addon pulls in) over the markup. Each case renders a field with id: 'f':

FAIL  Input                  aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]
FAIL  Input type=color       aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]
FAIL  DatePicker             aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]
FAIL  DatePicker dayFormat   aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]
FAIL  Input (no label)       aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]
PASS  Select                 aria-labelledby="f-label" dangling=[] axe=[]
PASS  Textarea               aria-labelledby="f-label" dangling=[] axe=[]
FAIL  Select (no label)      aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]
FAIL  Textarea (no label)    aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]
FAIL  DatePicker (no label)  aria-labelledby="f-label" dangling=["f-label"] axe=["aria-valid-attr-value"]

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 any Input or DatePicker story's Accessibility tab, which flags the violation on main and is clear on this branch. The repo has no unit-test harness, so I did not add one. tsc --noEmit and eslint src are clean before and after, and npm run build gives 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.

board

If you'd rather not receive contributions like this, reply no-more-prs on 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

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-io

snyk-io Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant