Direction
Tells the components inside it to lay out left to right or right to left, and to read the locale's conventions.
This project ships left to right
Silkware is configured with "rtl": false in components.json. Nothing in this site is mirrored, and no page wraps its content in a DirectionProvider. The component is installed so that products built with Silkware can support right-to-left languages such as Arabic and Hebrew. Turn it on in the application that needs it, as shown below.
Installation
pnpm dlx shadcn@latest add @silkware/directionTo copy the component by hand, install its dependency:
pnpm add react-aria-componentsThen copy the source into components/ui/direction.tsx:
"use client"
import * as React from "react"import { I18nProvider, useLocale } from "react-aria-components"
function DirectionProvider( props: React.ComponentProps<typeof I18nProvider> & { direction?: "ltr" | "rtl" }) { const { locale: currentLocale } = useLocale() let locale = props.locale if (!locale && props.direction) { locale = new Intl.Locale(currentLocale, { script: props.direction === "rtl" ? "Arab" : "Latn", }).toString() }
return <I18nProvider {...props} locale={locale} />}
function useDirection() { const { direction } = useLocale() return direction}
export { DirectionProvider, I18nProvider, useDirection, useLocale }Usage
import { DirectionProvider } from "@/components/ui/direction"<html lang="ar" dir="rtl"> <body> <DirectionProvider direction="rtl">{children}</DirectionProvider> </body></html>Two things have to agree. The dir attribute on the html element (or on a container) makes the browser lay out text and boxes right to left. DirectionProvider tells the React Aria components, such as the calendar, the toggle group and the menus, to arrange their own parts and arrow keys the same way. Set both. Without the provider, the React Aria components keep working from the browser's language. Without the dir attribute, text and layout stay left to right.
DirectionProvider wraps the React Aria I18nProvider. Give it direction to switch the direction of the current language, or locale to switch language and let the direction follow from it. Right-to-left languages such as ar and he resolve to right to left.
Put the provider as high as the direction changes, usually at the root of the application. You can nest one inside another to render a section in a different direction.
useDirection
useDirection returns the direction the components in the current provider use: "ltr" or "rtl". Use it when your own component needs to flip an icon or an offset.
import { useDirection } from "@/components/ui/direction"
function BackIcon() { const direction = useDirection() return direction === "rtl" ? <ArrowRightIcon /> : <ArrowLeftIcon />}The module also re-exports I18nProvider and useLocale from React Aria for convenience.
Examples
Direction
direction="rtl" mirrors the components inside. The toggle group above reads right to left, with the first item on the right.
Locale
Pass locale to change the language of the components that format dates and numbers. The calendar takes its month names, weekday letters, first day of the week and layout from ar.
نوفمبر 2026
| س | ح | ن | ث | ر | خ | ج |
|---|---|---|---|---|---|---|
Reading the direction
useDirection reads the value from the nearest provider, so each provider can carry its own direction.
Current direction: ltr
Current direction: rtl
Accessibility
DirectionProvider has no interface of its own, so it has no keys of its own. It changes how other components behave:
- In a right-to-left horizontal group, such as a Toggle Group, ArrowRight moves to the previous item and ArrowLeft to the next, matching the visual order.
- In a Calendar, the previous and next buttons and the arrow keys follow the reading direction.
React Aria provides:
- Direction-aware focus movement, popover placement (
startandendfollow the direction) and slider and calendar behaviour. - Localised labels and formats from the locale.
You provide:
- The
dirattribute onhtmlor on the container, and thelangattribute that matches the language, so screen readers choose the right voice. - Translated text for every label, placeholder and
aria-label. The provider does not translate your own strings. - Layout that uses logical properties (
ms-,me-,ps-,pe-,start,end) instead of left and right, so your own components mirror too.
Guidelines
When to use
- In an application that is translated into a right-to-left language.
- For a section that shows content in another direction than the page, such as an Arabic customer name in an English document.
When not to use
- In an application that is only left to right. The default direction already applies, and the provider adds nothing.
- To change the language of text. Translate the text, and set the
langattribute. - To mirror a single icon. Read
useDirectionand choose the icon yourself.
Content
- Translate all visible text and every accessible name, not only the main labels.
- Keep numbers, product names and codes as they are: "PO-4821" stays left to right inside right-to-left text.
- Do not mirror icons that show real-world things, such as a clock or a check mark. Mirror only icons that show direction, such as arrows.
Pair the provider with the attribute
اختر الفترة الزمنية للتقرير
Set dir on the container and wrap the components in DirectionProvider.
اختر الفترة الزمنية للتقرير
Don’t rely on the provider alone. The text and the layout stay left to right.
API reference
DirectionProvider
Renders a React Aria I18nProvider and accepts its props. When you pass direction and no locale, it builds a locale from the current one with the Arabic script for "rtl" and the Latin script for "ltr".
| Prop | Type | Default | Description |
|---|---|---|---|
direction? | "ltr" | "rtl" | None | The direction to use. Ignored when locale is set. |
locale? | string | None | A BCP 47 language tag such as ar or he-IL. The direction follows from the language. |
children | ReactNode | None | The components that use the direction. |
useDirection
A hook that returns "ltr" or "rtl" from the nearest provider. It takes no arguments.
I18nProvider and useLocale
The file re-exports React Aria's I18nProvider and useLocale unchanged, so you can set a locale without a direction and read locale and direction from one import. DirectionProvider is built on both.