Skip to content

Fix Checkbox labels inside Field#3878

Open
cyphercodes wants to merge 1 commit into
tailwindlabs:mainfrom
cyphercodes:fix-checkbox-label-htmlfor
Open

Fix Checkbox labels inside Field#3878
cyphercodes wants to merge 1 commit into
tailwindlabs:mainfrom
cyphercodes:fix-checkbox-label-htmlfor

Conversation

@cyphercodes
Copy link
Copy Markdown

Fixes #3876.

Summary

  • Omit Label's rendered for attribute when the resolved target is not a labelable HTML element, avoiding Chrome's warning for Field + Label + Checkbox.
  • Keep label click/focus behavior by resolving the internal target id even when for is not rendered.
  • Use the target's role attribute when forwarding label clicks to ARIA checkbox/radio/switch controls.
  • Add a checkbox regression test that verifies no invalid for attribute is rendered, label clicks still toggle/focus the checkbox, and form data is preserved.

Test plan

  • CI=true npm run react test checkbox label
  • npx tsc -p packages/@headlessui-react/tsconfig.json --noEmit --pretty false
  • npx prettier --check packages/@headlessui-react/src/components/label/label.tsx packages/@headlessui-react/src/components/checkbox/checkbox.test.tsx packages/@headlessui-react/src/utils/dom.ts

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

@cyphercodes is attempting to deploy a commit to the Tailwind Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

<Label> + <Checkbox> inside <Field> triggers Chrome "label's for attribute doesn't match any element id" warning

1 participant