Skip to content

[radio-button] Render content labels as a real label part (#376) - #378

Merged
MawiraIke merged 3 commits into
masterfrom
fix/radio-button-label-part
Jul 30, 2026
Merged

[radio-button] Render content labels as a real label part (#376)#378
MawiraIke merged 3 commits into
masterfrom
fix/radio-button-label-part

Conversation

@MawiraIke

@MawiraIke MawiraIke commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Closes #376.

What

Since the 2.29.x part migration, radio-button rendered a string :label as a bare text node: no label element, no rc-radio-button-label, the theme's padding-left and the caller's :label-style/:label-class silently ignored — and (unreported until now) no on-click, so clicking the label stopped toggling the radio.

Root cause

Not the :impl "empty" the issue originally blamed — it's part/part's string shortcut: a string part-value is returned verbatim, bypassing the impl, the theme, and post-props. Because :top-level-arg? true conflates the :label content argument with the :parts override mechanism, :label "text" (the universal case) takes the wholesale-replacement path. (Correction posted on the issue: the "component :style lands on the input" observation was pre-existing parity, not a regression — pre-migration also merged class/style/attr onto the input.)

The fix

  • New part/content? predicate (string | number | hiccup).
  • radio-button wraps content labels in the themed ::rb/label span with the content as :children — the theme (rc-radio-button-label via the automatic part class, padding-left, :label-style/:label-class) and the click handler all apply again. Map/fn part values keep their override semantics.
  • The label on-click rides :attr (where part/default actually emits handlers), restoring label-click toggling; the part structure declares the label's real :tag :span instead of :impl "empty".
  • The bootstrap theme's explicit "rc-radio-button-label" literal is dropped — theme/re-com-meta already adds it automatically, and keeping both produced a duplicated class once the label element actually rendered.

Testing

  • New test/re_com/radio_button_test.cljs: renders the component fn and walks the hiccup for the label part's props — asserts the element exists, the classes/styles/children/on-click all land, hiccup labels wrap, absent labels emit no part. RED on master (no label part in the tree), GREEN with the fix. Suite: 69 tests / 257 assertions, 0 failures.
  • Verified in the demo app (DOM shows the restored span with padding and working :label-style) and downstream in app usage against this branch via a :local/root override changes render with correct spacing and clickable labels.
  • Downstream note for app upgrades: apps that added wrapper-gap CSS workarounds for this bug (e.g. .rc-radio-button-wrapper {gap: 8px}) should remove them when bumping, or spacing doubles.

Sibling issue filed: #377checkbox has the same latent string-label bypass (invisible because its theme spaces via wrapper gap), fixable with the same part/content? pattern.

🤖 Generated with Claude Code

MawiraIke and others added 3 commits July 30, 2026 03:50
- A string :label must render as a real ::rb/label part carrying
  rc-radio-button-label + :label-class, the theme padding + :label-style,
  the label as its child, and an on-click (label clicks toggle — the
  pre-2.29 behaviour); hiccup labels wrap, absent labels render no part
- RED: part/part's string shortcut returns the label verbatim, so no
  label part exists in the tree

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- part/part's string shortcut returns a string part-value verbatim,
  bypassing impl, theme and post-props. Since :top-level-arg? conflates
  the :label content arg with the part override, every string/hiccup
  :label rendered as a bare text node: no rc-radio-button-label element,
  no theme padding, :label-style/:label-class silently ignored, and no
  on-click — label clicks stopped toggling the radio
- New part/content? predicate (string | number | hiccup); radio-button
  wraps content labels in the themed ::rb/label span (children), while
  map/fn part values keep their override semantics
- The on-click now rides :attr (part/default only emits class/style/attr),
  restoring label-click toggling; the part structure declares the label's
  real :tag :span instead of :impl "empty"

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…trap theme

- theme/re-com-meta already adds rc-radio-button-label automatically via
  part/css-class; keeping the literal produced a duplicated class once
  the label part actually rendered (#376)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@MawiraIke
MawiraIke merged commit 20e08b3 into master Jul 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant