Skip to content

[SUR-488] Fix borderless reverse-position radio/switch alignment - #480

Merged
jaieds merged 2 commits into
stagingfrom
fix/radio-button-borderless-reverse-alignment
Jul 17, 2026
Merged

[SUR-488] Fix borderless reverse-position radio/switch alignment#480
jaieds merged 2 commits into
stagingfrom
fix/radio-button-borderless-reverse-alignment

Conversation

@jaieds

@jaieds jaieds commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

PR #471 added reverse-position support for the bordered radio-button variant, but the new geometry applied to every reversePosition usage:

  • the control moved from flush left-0 to left-3 ml-0.5 (~14px inset)
  • the wrapper gained pl-16/pl-12 padding

For borderless reversed usage — e.g. the SureEmails onboarding template's useSwitch + reversePosition opt-in — this shifted the switch right and misaligned it with surrounding form fields.

Fix

Scope the inset geometry to borderOn. Without a border, the legacy layout is restored: control flush at left-0, content offset via ml-10 (switch) / ml-4 (radio). The nested ternary is extracted into a controlPositionClass variable to satisfy no-nested-ternary.

Case Before this PR After
reversePosition + borderOn control inset 14px (intended) unchanged
reversePosition borderless control inset 14px (regression) flush left (pre-#471 layout)
default (not reversed) unchanged unchanged

Testing

  • Templates/Onboarding/Spam story: switch left edge aligns with the field above again
  • Atoms/RadioButton bordered reverse-position stories (radio + switch): inset intact
  • eslint, tsc -b, and radio-button storybook interaction tests pass

jaieds added 2 commits July 17, 2026 16:35
The bordered reverse-position layout (left-3 inset + pl-16/pl-12 wrapper
padding) applied to every reversePosition usage, shifting borderless
reversed controls ~14px right and misaligning them with surrounding
fields (visible in the SureEmails onboarding template). Scope the inset
to borderOn and restore the legacy flush-left layout otherwise.
@@ -341,6 +341,11 @@ export const RadioButtonComponent = (
'space-y-3': size === 'sm',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What: The addition of comments explaining the layout differences is useful, but consider also documenting how the controlPositionClass and controlSpacingClass are determined as they add some complexity.

Why: Clear documentation within the code helps current and future developers understand the layout logic and aids in maintenance, especially in component libraries where multiple developers may be involved.

How: You may enhance the comments to explain the conditions for borderOn and reversePosition affecting layout, and include a brief on the expected outcomes of each combination.

@@ -375,7 +380,7 @@ export const RadioButtonComponent = (
</div>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What: While updating the dependencies in the useEffect hook for reversePosition, borderOn, and useSwitch is beneficial, ensure that changes in these dependencies do not lead to unnecessary renders.

Why: Adding more dependencies to the useEffect may cause performance overhead if they frequently change and result in excessive re-renders. Optimize the state management logic to minimize updates where possible.

How: Evaluate if all added dependencies are vital for the side effects you are triggering. If some, like borderOn or useSwitch, are not frequently changing during component lifecycles, consider managing them with either state or derived state.

@jaieds
jaieds requested a review from imnavanath July 17, 2026 10:41
@jaieds
jaieds merged commit c29afc5 into staging Jul 17, 2026
8 checks 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

Development

Successfully merging this pull request may close these issues.

2 participants