Reading direction
One provider, one prop. Flip it and the Radix keys, the slider's start edge, the tab shoulders and the words all turn round together. Click a tab and press the arrow keys before and after.
Tells every Radix part, every drawing and every logical property which way the page reads. One provider at the root of a right-to-left page (or on an island inside a left-to-right one) turns arrow keys, sub-menus, slider edges, tab shoulders and hand-drawn strokes round together.
npx shadcn@latest add @wobko/directionFirst time here? Add the registry to components.json first. How to install
One provider, one prop. Flip it and the Radix keys, the slider's start edge, the tab shoulders and the words all turn round together. Click a tab and press the arrow keys before and after.
Tabs, a menu with a sub-menu, a slider and a table, in Arabic. Tab and arrow keys run right to left, the sub-menu opens with ArrowLeft, the slider starts at its right edge, the table columns read from the right.
A breadcrumb, a carousel and a pager, in Hebrew. The separators and arrows are the same drawings as in English: direction glyphs flip themselves, so the first slide sits at the right and ArrowLeft moves on to the next.
The pad hangs on the right, where a right-to-left page keeps its margin: side="right" is a physical side, so you choose it. The clip, the highlighter, the bracket, the panel icon and the sheet on a phone all follow.
Your own widgets can read the direction too. This pager decides which arrow key goes forward from useDirection(), and its arrow drawings flip themselves. The English block is a left-to-right island inside the Hebrew page: it has its own provider, and its popover opens left to right.
Sets the direction for Radix, the ink engine and the DOM. It renders a layout-neutral wrapper (`display: contents`) that carries `dir`; portalled content (popovers, dialogs, sheets, tooltips, menus) leaves the wrapper, so it is handed the direction through the ink scope and carries `dir` itself.
| Prop | Type | Default | Description |
|---|---|---|---|
| direction | "ltr" | "rtl" | - | The reading direction. Leave it out to follow the page: the nearest `dir` above the provider, else `<html dir>`, read after mount and whenever it changes (the first render is `ltr` on the server and in hydration). |
| dir | "ltr" | "rtl" | - | Upstream shadcn's prop name for `direction`. `direction` wins when both are given. |
| asChild | boolean | false | Put `dir` on your own single child (a `main`, a `section`) instead of the wrapper element. |
| className | string | "contents" | The wrapper is `contents`; give it a display utility (`grid`, `flex`) to make it a real box. |
`useDirection(localDir?)` returns the direction of the nearest provider, `"ltr"` without one. It is Radix's own hook, so it stays in step with the keys and thumbs of every Radix part. A `localDir` wins, the way a `dir` prop does on a Radix root.
| Prop | Type | Default | Description |
|---|---|---|---|
| localDir | "ltr" | "rtl" | - | A direction that overrides the context, typically a prop of your own component. |
The files the CLI copies into your project.
Loading the source