ui icon indicating copy to clipboard operation
ui copied to clipboard

Support for RTL

Open nahasco opened this issue 1 year ago • 9 comments

Thanks for this great project. It has been very useful so far.

Unfortunately, it does not support RTL layouts out of the box. I use dir='rtl' for this RTL project. What it does is structure everything from right to left instead of left to right. For example in display: flex the div at the top of the structure will be placed on the left side and the one on the bottom to its left.

Most components do not support this, for example the alert components use padding to place the icon on the left causing it to have no effect in RTL, others don't switch order for some reason like the select component.

I hope the components are tuned a bit to support RTL and further improve the accessibility of this library.

Thanks!

nahasco avatar Jun 03 '23 09:06 nahasco

Just noticed dir:rtl is assigned to the select components and maybe to other components too. How would I remove that and why not just remove it from all components and give the user the freedom to assign the direction as needed?

nahasco avatar Jun 03 '23 10:06 nahasco

Use https://www.radix-ui.com/docs/primitives/utilities/direction-provider at the root of your app

Ow you're right some components are using physical, directional properties like pl-* instead of logical properties ps-*

sadeghbarati avatar Jun 03 '23 11:06 sadeghbarati

This is quite unfortunate.

I have been building using shadcn for quite some time and overlooked the rtl support.

I would be great to have any updates about this. I haven't come across anything yet that allows you to control.

MhndMousa avatar Sep 19 '23 14:09 MhndMousa

Since chadcn ui uses radix-ui you can simply solve it by wrapping your root app component with radix-ui "Direction Provider" component and make the value of it's parameters dir="rtl"

import "../@/styles/global.css";
import { DirectionProvider } from "@radix-ui/react-direction";
import { AppProps } from "next/app";

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <DirectionProvider dir="rtl">
      <Component {...pageProps} />
    </DirectionProvider>
  );
}

export default MyApp;

You could install the package via npm:

npm install @radix-ui/react-direction

The reference

AhmedGamal73 avatar Jan 10 '24 02:01 AhmedGamal73

just replace the existing style

data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0

with the following:

data-[state=checked]:ltr:translate-x-5 data-[state=unchecked]:ltr:translate-x-0 data-[state=checked]:rtl:-translate-x-5 data-[state=unchecked]:rtl:-translate-x-0

mohamedtsx avatar Jan 29 '24 14:01 mohamedtsx

For people who are still wondering how to make the shadcn carousel's direction RTL, you just need to pass the direction option like this:

<Carousel
    opts={{
        direction: "rtl",
    }}
>

arshaan-abh avatar Apr 24 '24 07:04 arshaan-abh

For people who are still wondering how to make the shadcn carousel's direction RTL, you just need to pass the direction option like this:

<Carousel
    opts={{
        direction: "rtl",
    }}
>

this works!, thanks.

e-Naeim avatar May 01 '24 11:05 e-Naeim

Many components do not support RTL, and we had to handle each one individually. I tried using DirectionProvider from Radix, but it did not work correctly. I hope RTL support will be fully integrated in the future.

mhl98 avatar May 17 '24 10:05 mhl98

Many components do not support RTL, and we had to handle each one individually. I tried using DirectionProvider from Radix, but it did not work correctly. I hope RTL support will be fully integrated in the future.

RTL is supported.

arshaan-abh avatar May 17 '24 14:05 arshaan-abh

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jun 29 '24 23:06 shadcn

i tried @radix-ui/react-direction as comments suggest but its not working , it will be great shadcn added rtl support

Beebox7Plus avatar Jul 01 '24 08:07 Beebox7Plus

i tried @radix-ui/react-direction as comments suggest but its not working , it will be great shadcn added rtl support

Try this: https://github.com/shadcn-ui/ui/issues/530#issuecomment-2074252042

arshaan-abh avatar Jul 01 '24 11:07 arshaan-abh

This is just for carousel component or few more, I have tried it it woks

https://github.com/shadcn-ui/ui/issues/530#issuecomment-2074252042

But when I am implementing using @radix-ui/react-direction, manually I need to add the dir to the html tag

guptaashwanee avatar Jul 14 '24 06:07 guptaashwanee