shadcn.io is not affiliated with official shadcn/ui
Shadcn Direction for React
Set left-to-right or right-to-left flow for a subtree.
StartltrEnd
Installation
bunx --bun shadcn@latest add https://kit.dev/r/aria/direction.jsonnpx shadcn@latest add https://kit.dev/r/aria/direction.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/direction.jsonyarn shadcn@latest add https://kit.dev/r/aria/direction.jsonInstall the following dependencies:
bun add react-aria-componentsnpm install react-aria-componentspnpm add react-aria-componentsyarn add react-aria-componentsCopy and paste the following code into your project.
"use client";
import type React from "react";
import { I18nProvider, useLocale as useRacLocale } from "react-aria-components";
export { I18nProvider } from "react-aria-components";
export const DirectionProvider = (
props: React.ComponentProps<typeof I18nProvider> & {
direction?: "ltr" | "rtl";
}
) => {
const { direction, locale: localeProp, children, ...rest } = props;
const { locale: currentLocale } = useRacLocale();
let locale = localeProp;
if (!locale && direction) {
locale = new Intl.Locale(currentLocale, {Update the import paths to match your project setup.
Usage
import { DirectionProvider } from "@/components/ui/direction";<DirectionProvider direction="ltr">
<p>Content inherits the provided direction.</p>
</DirectionProvider>import { useDirection } from "@/components/ui/direction";
const Example = () => {
const direction = useDirection();
return <div>Current direction: {direction}</div>;
};See the RTL configuration guide for document-level direction. This page does not replace locale setup.
Demos
Rtl
Right-to-left direction. Logical ms / me spacing follows the reading direction.