Skip to content

fix: forward form-control attributes to buttons - #297

Draft
l4u532 wants to merge 2 commits into
starc007:mainfrom
l4u532:fix/form-control-attributes
Draft

l4u532 wants to merge 2 commits into
starc007:mainfrom
l4u532:fix/form-control-attributes

Conversation

@l4u532

@l4u532 l4u532 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

tl;dr

  • Switch and the Select trigger ignored a caller's ID, so an external label could not point at them. All four form controls dropped most ARIA attributes and all data attributes. Their buttons now receive them.
  • Callers can name a radio or checkbox explicitly while keeping its description separate. Switch still accepts ariaLabel.

Reproduction

Render a switch beside <label htmlFor="updates">Email updates</label> and pass id="updates" to Switch. Clicking the label now toggles the switch. A Select trigger accepts the same label pattern. Clicking its label twice opens and then closes the listbox.

Before and after

The same label presses leave the switch off and the listbox closed on the left. On the right, the switch turns on and the listbox opens. Captured 2026-11-29 against c0944430 and aeb528cc.

Chrome before-and-after comparison

iPad Safari before-and-after comparison

Implementation

RadioGroupItem, Switch, Checkbox, and SelectTrigger forward attributes to their buttons. The components still own their state attributes and activation handlers. Radio keyboard navigation is unchanged. An empty ID uses the generated ID.

For Radio and Checkbox, aria-labelledby takes precedence over aria-label and the built-in name. aria-describedby adds external text alongside the built-in description. For Switch, aria-label takes precedence over ariaLabel. For Select, include the visible value or placeholder in an explicit accessible name.

Select uses the mounted trigger ID for listbox labelling, placement, and focus return. Dismissal treats the linked label as part of the trigger interaction. The 14 docs pages that ship the changed files have refreshed dates.

Browser results

Measured on 2026-11-29 with Playwright, Chrome DevTools, SafariDriver, and iPad Safari on iPadOS 26.5. The before and after fixtures compare attribute forwarding and external label activation.

Check Chrome Safari
Button IDs, ARIA and data attributes Passed. DevTools exposed “Basic, current plan” with description “One workspace.” Passed. SafariDriver confirmed the attributes and ID references. iPad exposed the updated names. Spoken descriptions were unverified.
Label activation Passed. The external switch label toggled it and the external Select label opened and closed it. Passed by touch on iPad. Desktop pointer results were unverified because SafariDriver clicks were inconsistent.
Keyboard and focus Passed. Space toggled the controls. Radio skipped a disabled option. Select opened, picked an option, and returned focus on Escape. Passed for Select keyboard open and focus return on desktop. Full Tab order and radio arrow navigation were unverified.
Select ID change and placement Passed. The listbox kept the matching ID after a change and opened above with 5 px below. Passed. SafariDriver read matching IDs after a change and an above-trigger listbox with 5 px below.
Responsive layout and touch Passed at 375px and with iPhone touch emulation. Passed at the iPad viewport. Phone-width layout was unverified.
Reduced motion Passed. The listbox transform stayed none over 21 sampled frames. Unverified. The system preference was unchanged.
Initially open, custom ID Failed before hydration. The server-rendered listbox references the generated ID. After hydration the reference resolves to the mounted trigger. Hydrated link passed. JavaScript-disabled Safari was unverified.

The local code review also found that an external native label picked up the built-in description. Chrome and iPad Safari confirmed the corrected names now contain only the label text. Chrome confirmed that a second press on a Select label keeps the list open until activation, then closes it once.

Chrome also checked Switch naming precedence, absent and empty attributes, controlled values, and Checkbox mixed state. It exercised approval choices, signup, scheduler controls, table selection, Card, Bookshelf, Wheel Picker, Crash, and Slide.

Test plan

  • Run bun run check and bun test. The accessibility suite has 243 passing tests.
  • Open the Switch preview and click Enable notifications. Click Framework twice in the Select preview.
  • Inspect the described Radio and Checkbox previews. Their accessible names and descriptions are separate. Click Weekly digest in the Checkbox preview: the external label toggles the checkbox.
  • Add an id, aria-invalid, or data-testid and inspect the button. The attributes appear on the same element as the control state.

@l4u532

l4u532 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Updated in 2bc7f1e6.

  • Checkbox description preview. Weekly digest is a native <label htmlFor> again, so a click on the text toggles the checkbox. In 91743faa it was a <span> named through aria-labelledby, and a click on it did nothing. The external IDREF case stays covered in tests/a11y.test.tsx.
  • Description. The tl;dr now says that only Switch and the Select trigger ignored a caller's ID. Checkbox and Radio already forwarded it. "Radio keyboard navigation is unchanged" replaces the claim about one roving Tab stop. The test plan adds the Weekly digest click.

Readings on 2026-11-30, 91743faa and 2bc7f1e6 side by side:

Check Chrome 158 (mouse and touch emulation) iPad Safari (iPadOS 26.5 simulator)
Click or tap on "Weekly digest" 91743faa: no change. 2bc7f1e6: toggles. 91743faa: no change. 2bc7f1e6: toggles.
Accessible name and description "Weekly digest", described by "A summary of activity every Monday.", in both revisions Name "Weekly digest" in both revisions
Space on the focused checkbox Toggles in both revisions Not rerun

bun run check (196 registry components) and bun test (243 tests) pass.

@l4u532
l4u532 force-pushed the fix/form-control-attributes branch 6 times, most recently from f064c41 to c59c137 Compare December 2, 2026 20:44
@l4u532
l4u532 force-pushed the fix/form-control-attributes branch from c59c137 to 35f7203 Compare December 4, 2026 14:46

This branch has not been deployed

No deployments
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