Skip to content

fix(FieldLabel): nest description inside label so clicking it toggles the control - #4152

Closed
is-jain wants to merge 2 commits into
meta:mainfrom
is-jain:fix/checkboxinput-clickable-description
Closed

is-jain wants to merge 2 commits into
meta:mainfrom
is-jain:fix/checkboxinput-clickable-description

Conversation

@is-jain

@is-jain is-jain commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

CheckboxInput's description text sits outside the <label> element as a sibling <span>, so clicking it does nothing — only clicking the label text toggles the checkbox. FieldLabel is shared by CheckboxInput, Switch, and Field, so the same gap exists on Switch.

Fix

Nest the description inside the <label>/<span> element FieldLabel renders, instead of rendering it as a sibling. Native label-click activation then covers the description too, matching how clicking the label text already works.

To keep the description on its own line without introducing an extra wrapper element (which would have shifted getByText(label).tagName off LABEL in existing tests), the label switches from a single-line flex row to a wrapping flex row (flexWrap: wrap) with the description given flexBasis: 100%, forcing it onto its own line.

This only affects isGroupLabel labels (radiogroups) in that the description now nests inside the group's <span> too — harmless, since a <span> never had click-to-activate behavior regardless of nesting.

Testing

  • Added works when clicking on the description tests to CheckboxInput.test.tsx and Switch.test.tsx, mirroring the existing works when clicking on the label tests.
  • Added a structural test to FieldLabel.test.tsx asserting the description is contained within the label element.
  • Full existing suites for FieldLabel, CheckboxInput, Switch, and Field (117 tests) pass.

Closes #4132

…ivates the control

CheckboxInput, Switch, and Field render the description as a sibling
span after the <label> instead of inside it, so clicking description
text does nothing while clicking the label text toggles the control.
Nest the description inside the label element (wrapping the row of
label+icon+badge+tooltip in a flex-wrap row so the description still
gets its own line) so native label-click activation covers it too.

Fixes meta#4132
@vercel

vercel Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 22, 2026 12:56am

Request Review

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 22, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 22, 2026
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Modified Components

CheckboxInput
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 449 -
Complexity N/A Very High (45) -
Field
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 519 -
Complexity N/A Very High (32) -
Switch
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 388 -
Complexity N/A Very High (43) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

CI caught a regression: nesting the description inside a group label
(isGroupLabel, used by InputGroup/CheckboxList/RadioList) folded the
description text into the group's accessible name, since aria-labelledby
computes the name from all descendant text of the referenced element.

Only nest the description for the single-control <label> case, where the
click-to-activate fix is actually needed. A group's <span> never had
native click activation to begin with, so keep it as a sibling there,
matching pre-fix behavior exactly.

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — the click-to-toggle fix is correct and well-tested for CheckboxInput and Switch, and gating the group-label case (keeping the description a sibling so it doesn't fold into the group's aria-labelledby) is exactly right.

My one blocking concern is scope: the fix is applied through shared FieldLabel, so it also affects Field-backed text inputs (TextInput, Selector, etc.), not just checkbox/switch. For a text input, the associated <label htmlFor> supplies the input's accessible name — so nesting the description inside it makes the input's accessible name become "Label + full description sentence," while the description is also wired via aria-describedby. Net effect for text inputs: name pollution + double announcement. I confirmed this by rendering the Field path in jsdom (accessible name picks up the description text).

Clicking a text input's label only focuses it — there's no toggle benefit — so nesting the description there is all cost, no benefit.

Requested changes:

  1. Scope the nesting to click-activatable single controls (checkbox / switch / radio item) only — e.g. an opt-in flag set by those components — and keep Field-backed text inputs' description as a sibling <span>.
  2. Add a toHaveAccessibleName / toHaveAccessibleDescription assertion on a Field/TextInput test to lock in that the description doesn't pollute the input's accessible name (the current suite doesn't assert this, which is why the regression is invisible).

Non-blocking: since description is a ReactNode, worth a note/guard that it shouldn't contain interactive elements when nested in a <label> (latent today).

Re-scope so only checkbox/switch/radio nest the description and this is a clean approve.

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The click-target fix is a real, worthwhile bug (clicking the description should toggle the control), and nesting it inside the <label> is the right instinct for native click activation. The group-label handling (keeping it a sibling so it doesn't fold into the group's aria-labelledby name) is well-reasoned. But I think the single-control path introduces an accessible-name regression that needs addressing before merge:

Double announcement of the description. For a single control (!isGroupLabel), the description is now nested inside the <label htmlFor={inputID}>. A control's accessible name is computed from its associated label's text content — so the description text now becomes part of the checkbox's name. Meanwhile XDSCheckboxInput.tsx:370 already builds aria-describedby from the same descriptionID:

if (description && !isLabelHidden) describedByParts.push(descriptionID);

So the description ends up in both the accessible name (via label nesting) and the accessible description (via aria-describedby). Screen readers will announce it twice — e.g. a checkbox "Email notifications" / "We'll send weekly digests" is announced as "Email notifications We'll send weekly digests, checkbox … We'll send weekly digests". The exact same concern you correctly avoided for group labels applies to single-control labels via htmlFor name computation.

Options to fix while keeping the click-target win:

  1. Nest the description in the label for the click target, but exclude it from the name — wrap it with aria-hidden won't work (it'd hide it from the aria-describedby reference too). Better: give the nested description role="presentation"-style exclusion isn't clean either.
  2. Preferred: keep the description a sibling (as today / as you do for groups) but make it clickable-to-toggle explicitly — e.g. the description <span> forwards click to the control (onClick → focus/click the input by descriptionID→inputID), or wrap label+description in a shared clickable container that isn't the <label> itself. That gets the click behavior without polluting the accessible name.
  3. Or: if nesting stays, drop the description from aria-describedby when it's inside the label (so it's name-only, not name+description) — but that changes the semantic role of the text from "description" to "name", which is probably wrong (it is a description).

Could you check the computed accessible name with a screen reader / axe (or a toHaveAccessibleName assertion that the description is NOT in the name)? A test asserting the single-control accessible name excludes the description would lock this down. The current tests cover click behavior and that the description is contained in the label, but not the name-duplication.

Happy to pair on option 2 if useful — it's the one that keeps your click fix without the name regression.

freddymeta added a commit that referenced this pull request Aug 1, 2026
…ut name pollution

Clicking a CheckboxInput/Switch description did nothing — the description
renders as a sibling <span> after the </label>, so native label-click
activation never covered it.

This is the review-adjusted take on #4152. Rather than nesting the
description inside the <label> (which folds it into the control's
accessible NAME and, combined with the existing aria-describedby, makes
screen readers announce it twice), keep the description a sibling and
forward its click to the control by id. The whole label area becomes a
hit target with no accessible-name change.

- New `FieldLabel` prop `hasClickableDescription` (default false), set by
  CheckboxInput and Switch. Off for `Field`-backed text inputs (clicking a
  text label only focuses — no toggle benefit — so no reason to risk the
  name) and ignored for group labels.
- Forwarding is a mouse-only convenience: the control stays the keyboard
  path, the description isn't focusable, so no new tab stop / a11y-tree
  change. Guarded so clicks on an interactive node inside a ReactNode
  description aren't hijacked.

Tests: click-the-description toggles (CheckboxInput + Switch); the control's
accessible name excludes the description while accessible description
includes it (toHaveAccessibleName/Description — the assertion the original
PR was missing); FieldLabel forwards only when opted in, never for the
default text-input path or group labels, and keeps the description a
sibling of the label.
cixzhang pushed a commit that referenced this pull request Aug 1, 2026
…ut name pollution (#4574)

* fix(field-label): forward description clicks to checkbox/switch without name pollution

Clicking a CheckboxInput/Switch description did nothing — the description
renders as a sibling <span> after the </label>, so native label-click
activation never covered it.

This is the review-adjusted take on #4152. Rather than nesting the
description inside the <label> (which folds it into the control's
accessible NAME and, combined with the existing aria-describedby, makes
screen readers announce it twice), keep the description a sibling and
forward its click to the control by id. The whole label area becomes a
hit target with no accessible-name change.

- New `FieldLabel` prop `hasClickableDescription` (default false), set by
  CheckboxInput and Switch. Off for `Field`-backed text inputs (clicking a
  text label only focuses — no toggle benefit — so no reason to risk the
  name) and ignored for group labels.
- Forwarding is a mouse-only convenience: the control stays the keyboard
  path, the description isn't focusable, so no new tab stop / a11y-tree
  change. Guarded so clicks on an interactive node inside a ReactNode
  description aren't hijacked.

Tests: click-the-description toggles (CheckboxInput + Switch); the control's
accessible name excludes the description while accessible description
includes it (toHaveAccessibleName/Description — the assertion the original
PR was missing); FieldLabel forwards only when opted in, never for the
default text-input path or group labels, and keeps the description a
sibling of the label.

* refactor(field-label): always forward description clicks, drop prop

Remove the `hasClickableDescription` opt-in. The description always forwards
clicks to its control via the shared interactive-skip + focus-vs-click logic:
`.focus()` for text-like inputs (matching native label behavior) and
`.click()` for checkbox/switch. Clicks on interactive content inside a
description (links, buttons) are left alone. Group labels still forward
nothing. Reuses FOCUS_INPUT_TYPES and INTERACTIVE_SELECTORS from the hooks
layer so the definition is shared, not duplicated.

* refactor(field-label): forward description clicks via useInputContainer

Use the existing useInputContainer hook to forward description clicks to
the control instead of hand-rolling the click logic. The hook already
skips nested interactive content and guards against text selection, so
the bespoke handler and the FOCUS_INPUT_TYPES export are dropped.

* fix(field-label): only attach the click-forward ref when forwarding is active

Attaching the container ref unconditionally would let useClickableContainer
stamp data-pressable-container on non-forwarding descriptions (group labels,
no inputID), which is in the interactive-selector set. Gate the ref on
forwardsDescriptionClick so those cases keep a plain span.

* fix(hooks): forward container clicks to popup triggers via click, not focus

useInputContainer classified controls by input.type, so a combobox rendered
as <input type="text"> (DateInput's field, role=combobox aria-haspopup=dialog)
got .focus() — which focuses it but never opens the picker (it opens on click,
with no onFocus opener). Detect popup triggers (role=combobox or aria-haspopup)
and .click() them before the type check. Plain text/number/textarea inputs are
unaffected and still .focus(). Fixes clicking a Field description forwarding to
a DateInput without opening the calendar.
@cixzhang

Copy link
Copy Markdown
Contributor

Closing — #4132 was fixed on Aug 2 by a different PR, which forwards description clicks to the associated control rather than nesting the description inside the <label>. Main's FieldLabel carries that behavior today, so CheckboxInput and Switch both toggle when the description is clicked.

The forwarding route was chosen over nesting because nesting pulls the description text into the control's accessible name. Your PR's flex-wrap approach avoided the extra wrapper element neatly, though — thanks @is-jain, and sorry it went stale before we got to it.

@cixzhang cixzhang closed this Aug 13, 2026
@github-actions
github-actions Bot deleted the fix/checkboxinput-clickable-description branch August 14, 2026 07:27

This branch was successfully deployed

1 active deployment
Preview — 7ceeea90 Deployed Jul 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] CheckboxInput: description isn't part of the clickable label — clicking it doesn't toggle the checkbox

2 participants