Skip to content

a11y/form-field-multiple-labels: label that wraps and references the same input (for=) counted twice #1249

Closed

Description

@deniskern

Summary

a11y/form-field-multiple-labels counts a <label> twice when it both wraps the input and references it with for=. The input has exactly one associated label (input.labels.length === 1), but squirrel reports "2 labels". axe-core's form-field-multiple-labels does not flag this pattern.

This is the default markup of Shopify Dawn-based product forms (variant radios), so it fires on every product page of such shops.

Minimal repro

<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Gift card amount selection form test page</title></head>
<body><main><h1>Gift card</h1>
<form><fieldset><legend>Amount</legend>
<label for="a"><input type="radio" name="amt" id="a" value="50"> 50</label>
<label for="b"><input type="radio" name="amt" id="b" value="100"> 100</label>
</fieldset></form></main></body></html>
python3 -m http.server 8765
squirrel audit http://localhost:8765/ --http -f json -o out.json

Actual

{"name":"form-field-multiple-labels","status":"warn","message":"2 input(s) with multiple labels","items":[{"id":"amt (2 labels)"}]}

Expected

No finding: each input has one label element. Associated labels should be collected as a set of label elements (HTMLInputElement.labels semantics), so a label that both wraps and references the same input counts once.

Controls (same version)

Markup Result Correct
<label><input></label> (wrap only) pass yes
<label for="x">X</label><input id="x"> (for only) pass yes
two <label for="y"> + <input id="y"> warn, 1 input yes
<label for="a"><input id="a"></label> (wrap + for) warn, 2 labels no

Possibly the same counting exists in sibling label rules; worth a look.

Version

squirrel 0.0.138 (macOS arm64), --http mode. Seen in production on www.bowlio.com product pages.

Triage

Confirmed against current main. packages/rules/src/a11y/form-field-multiple-labels.ts adds the count of label[for="<id>"] matches and then adds one more when input.closest("label") exists. A label that both wraps the input and points at it with for= is counted by both paths, so one label element reads as two.

Acceptance Criteria

  • <label for="a"><input id="a"></label> produces no form-field-multiple-labels finding.
  • The repro page above passes the rule.
  • Two distinct label elements on one input (two <label for> or one wrapping plus one for) still warn, with an accurate label count.
  • The wrap-only and for-only controls still pass.
  • A regression test covers the wrap-plus-for case, and the rule docs mention it if they describe label counting.

Activity

  1. added
    bug
    size: XS
    rules
    on Oct 29, 2026
  2. added theissue type on Oct 29, 2026
  3. nc9 commented on Oct 30, 2026

    @nc9
    Contributor

    Fixed in v0.0.142 (1ea94aae), via the stacked release PR #1331.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: XS

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions