[SUR-488] Fix borderless reverse-position radio/switch alignment - #480
Conversation
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', | |||
There was a problem hiding this comment.
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> | |||
There was a problem hiding this comment.
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.
Summary
PR #471 added reverse-position support for the bordered radio-button variant, but the new geometry applied to every
reversePositionusage:left-0toleft-3 ml-0.5(~14px inset)pl-16/pl-12paddingFor borderless reversed usage — e.g. the SureEmails onboarding template's
useSwitch + reversePositionopt-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 atleft-0, content offset viaml-10(switch) /ml-4(radio). The nested ternary is extracted into acontrolPositionClassvariable to satisfyno-nested-ternary.reversePosition+borderOnreversePositionborderlessTesting
Templates/Onboarding/Spamstory: switch left edge aligns with the field above againAtoms/RadioButtonbordered reverse-position stories (radio + switch): inset intacttsc -b, and radio-button storybook interaction tests pass