Repository navigation
Conversation
…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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis ReportModified ComponentsCheckboxInput
Field
Switch
Bundle Size Summary
Accessibility AuditStatus: 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
left a comment
There was a problem hiding this comment.
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:
- 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>. - Add a
toHaveAccessibleName/toHaveAccessibleDescriptionassertion 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
left a comment
There was a problem hiding this comment.
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:
- Nest the description in the label for the click target, but exclude it from the name — wrap it with
aria-hiddenwon't work (it'd hide it from the aria-describedby reference too). Better: give the nested descriptionrole="presentation"-style exclusion isn't clean either. - 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 bydescriptionID→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. - Or: if nesting stays, drop the description from
aria-describedbywhen 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.
…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.
…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.
|
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 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. |
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.FieldLabelis shared byCheckboxInput,Switch, andField, so the same gap exists onSwitch.Fix
Nest the description inside the
<label>/<span>elementFieldLabelrenders, 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).tagNameoffLABELin existing tests), the label switches from a single-line flex row to a wrapping flex row (flexWrap: wrap) with the description givenflexBasis: 100%, forcing it onto its own line.This only affects
isGroupLabellabels (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
works when clicking on the descriptiontests toCheckboxInput.test.tsxandSwitch.test.tsx, mirroring the existingworks when clicking on the labeltests.FieldLabel.test.tsxasserting the description is contained within the label element.FieldLabel,CheckboxInput,Switch, andField(117 tests) pass.Closes #4132