shadcn.io is not affiliated with official shadcn/ui
The provider sets reading direction for one region and leaves the rest of the page alone.
Wrap a subtree when only that region reads the other way, and set dir on the same element so the CSS follows. One field on its own can take dir on an Input and skip the provider. In React, Base UI menus and arrow keys read the provider, which the attribute alone does not set.
Installation
Anatomy

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
The same Start and End row, but the provider direction is rtl and the wrapper sets dir to match. useDirection reports rtl, Start moves to the right, and the end margin pushes End toward the left. Set both. One without the other leaves either the components or the CSS unflipped.
FAQ
How do I set up a right-to-left (RTL) layout in React?
Set dir="rtl" on the html element and wrap the app in DirectionProvider with direction="rtl". The attribute flips the CSS and Tailwind's rtl: variants; the provider tells the components, so popovers, sliders and arrow keys follow the reading direction. The RTL guide covers the whole setup.
Why do I need DirectionProvider if the html tag already has dir?
Because the two do different jobs. The dir attribute only changes the layout; the components read the direction from the provider to place their menus and to map the left and right arrow keys. With only one of them, the page is half mirrored.
How do I read the current text direction in a component?
Call useDirection() inside the provider: it returns "ltr" or "rtl". Use it to swap an icon or to set dir on an element you render yourself.
How does DirectionProvider relate to the locale?
It only sets the direction: date and number formatting follow each component's own locale prop.
API Reference
DirectionProvider
direction?"ltr" | "rtl"
The reading direction of the text.
- Type
"ltr" | "rtl"- Default
"ltr"
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
useDirection
With other components
- Free▼
Dropdown Menu
MenusPanels open the other way
- Free▼✓
Select
SelectionList follows reading
- Free
Slider
ControlsArrow keys reverse
- Free
Sheet
OverlaysSlides from the start
- Free
Tabs
NavigationArrows follow reading
- Free
Menubar
MenusSubmenus open inward
Related
- Free
Accordion
DisclosureChevrons stay on the end
- Free
Card
LayoutForms that mirror
- Free
Field
InputsLabels flip with dir
- Free▲▼✓
Native Select
SelectionInherits html dir
- Free‹…›
Pagination
NavigationNext stays at the end
- Free//
Breadcrumb
NavigationTrail reads backward