#8198·ui

[bug]: the directions of the switch

Author: MoOsama6141Created Sep 11, 2025Updated Sep 27, 2026
Labelsbugstale?

Describe the bug

the switch direction is not working well it has an issue when changing the language from the arabic to english or the opposite it only reads one direction

Affected component/components

SwitchPrimitives.Thumb

How to reproduce

import * as React from 'react'; import * as SwitchPrimitives from '@radix-ui/react-switch';

import { cn } from '@/lib/utils'; import i18n from '@/lib/i18n/i18n';

const dir = i18n.dir();

const Switch = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef

(({ className, ...props }, ref) => ( <SwitchPrimitives.Root dir={i18n.dir()} className={cn( 'peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:text-green-500 data-[state=unchecked]:bg-input', className, )} {...props} ref={ref}

<SwitchPrimitives.Thumb
  className={`pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform ${i18n.dir() === 'rtl' ? ' data-[state=checked]:-translate-x-4' : ' data-[state=checked]:translate-x-4'} data-[state=checked]:bg-green-500  data-[state=unchecked]:translate-x-0`}
/>

</SwitchPrimitives.Root> )); Switch.displayName = SwitchPrimitives.Root.displayName;

export { Switch };

Codesandbox/StackBlitz link

No response

Logs

bash

System Info

bash
At first render Tailwind only generates classes it sees in the code so You’re conditionally including either
data-[state=checked]:-translate-x-4 (RTL) or data-[state=checked]:translate-x-4 (LTR).
Tailwind doesn’t see both at once → whichever branch doesn’t run on first render never makes it into the compiled CSS.
So when you later switch languages (and dir flips), the required class isn’t in your CSS → the thumb “breaks” visually.  tailwind only read the case once and when we change the language it does not rerender the component so it reads only one so the solution to make it rerendered on every change in the languge [direction]

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues