Direction Provider
A context that switches components to right-to-left behavior.
التعليمات التي يتبعها النموذج في كل محادثة.
hero.tsx
Usage guidelines
- Set
diras well:DirectionProvidertells components which way the inline axis runs, so arrow keys, slider values and popup placement follow it. In the example above, right to left makesArrowLeftmove to the next tab and raise the slider value. The provider renders no element and does not change CSS. Set the HTMLdirattribute on the same subtree, usually on<html>, so layout, logical utilities and:dir()selectors follow. - Wrap the app once: Put one provider near the root with the locale's direction. Nest another only for a region written in a different direction from the page.
- Pass
dirto popups in a nested region: Popups render in a portal under<body>, outside the region'sdir. Read the direction withuseDirectionfrom a component inside the provider and pass it asdirto the content part of every popup in the region, including submenus and popups opened from another popup. A page that setsdiron<html>needs no extra step. - Write direction-neutral styles: Use logical utilities such as
ps-*,me-*,start-*andtext-startfor spacing, offsets, borders and alignment, so one class list serves both directions. Caller overrides use the same family, becausecndoes not mergepl-*withps-*. - Read the direction only when a value must leave CSS:
useDirectionreturns'ltr'or'rtl'for code that computes geometry or passesdirto portaled content. Prefer a:dir(rtl)orrtl:variant for anything CSS can express.
Anatomy
tsx
tsx
Examples
Popups in a right-to-left region
Placement and keyboard read the provider, so the submenu opens toward the left and ArrowLeft opens it. Text, logical utilities and :dir() read the DOM instead, and a portaled popup inherits the direction and language of <body>. Each menu here receives dir from useDirection and lang="ar", so its items, submenu chevron and screen-reader language all match the region.
portaled-popup.tsx
API reference
DirectionProvider
Enables RTL behavior for Dify UI and Base UI components. Doesn't render its own HTML element.
| Prop | Type | Default | Details |
|---|---|---|---|
children | React.ReactNode | No default | |
direction | 'ltr' | 'rtl' | 'ltr' | |
useDirection
Returns
'ltr' | 'rtl'